gnosticdev commited on
Commit
f560070
·
verified ·
1 Parent(s): 6caa0a7

Update conver.py

Browse files
Files changed (1) hide show
  1. conver.py +6 -6
conver.py CHANGED
@@ -14,7 +14,7 @@ from threading import Thread
14
 
15
  @dataclass
16
  class ConversationConfig:
17
- max_words: int = 3000
18
  prefix_url: str = "https://r.jina.ai/"
19
  model_name: str = "meta-llama/Llama-3-8b-chat-hf"
20
 
@@ -57,7 +57,7 @@ class URLToAudioConverter:
57
  if not text:
58
  raise ValueError("Input text cannot be empty")
59
  try:
60
- prompt = f"{text}\nConvierte este texto en un diálogo de podcast en español entre Anfitrión1 y Anfitrión2. El diálogo debe ser extenso,de caracter conspiranoico, sin negar omponer en duda nada de las cosas extrañas. detallado y atractivo, con al menos 20 intercambios por anfitrión, manteniendo un tono conversacional, expresivo y natural. Usa un lenguaje claro y adaptado a una audiencia hispanohablante. Devuelve SOLO:\nAnfitrión1: [texto]\nAnfitrión2: [texto]\n..."
61
  response = self.llm_client.chat.completions.create(
62
  messages=[{"role": "user", "content": prompt}],
63
  model=self.config.model_name
@@ -67,7 +67,7 @@ class URLToAudioConverter:
67
  for line in raw_text.split('\n'):
68
  if ':' in line:
69
  speaker, _, content = line.partition(':')
70
- if speaker.strip() in ("Host1", "Host2"):
71
  dialogue["conversation"].append({
72
  "speaker": speaker.strip(),
73
  "text": content.strip()
@@ -82,7 +82,7 @@ class URLToAudioConverter:
82
  try:
83
  for i, turn in enumerate(conversation_json["conversation"]):
84
  filename = output_dir / f"segment_{i}.mp3"
85
- voice = voice_1 if turn["speaker"] == "Host1" else voice_2
86
  tmp_path = await self._generate_audio(turn["text"], voice)
87
  os.rename(tmp_path, filename)
88
  filenames.append(str(filename))
@@ -156,7 +156,7 @@ class URLToAudioConverter:
156
  return await self._process_to_audio(conversation, voice_1, voice_2)
157
 
158
  async def raw_text_to_audio(self, text: str, voice_1: str, voice_2: str) -> Tuple[str, str]:
159
- conversation = {"conversation": [{"speaker": "Host1", "text": text}]}
160
  return await self._process_to_audio(conversation, voice_1, voice_2)
161
 
162
  async def _process_to_audio(
@@ -182,4 +182,4 @@ class URLToAudioConverter:
182
  f"{turn['speaker']}: {turn['text']}"
183
  for turn in conversation["conversation"]
184
  )
185
- return output_path, text_output
 
14
 
15
  @dataclass
16
  class ConversationConfig:
17
+ max_words: int = 5000 # Aumentado para diálogos más largos
18
  prefix_url: str = "https://r.jina.ai/"
19
  model_name: str = "meta-llama/Llama-3-8b-chat-hf"
20
 
 
57
  if not text:
58
  raise ValueError("Input text cannot be empty")
59
  try:
60
+ prompt = f"{text}\nConvierte esto en un diálogo de podcast en español entre Anfitrión1 y Anfitrión2. Genera un diálogo extenso y detallado, con respuestas completas y naturales, como una conversación real de podcast. Devuelve SOLO:\nAnfitrión1: [texto]\nAnfitrión2: [texto]\n..."
61
  response = self.llm_client.chat.completions.create(
62
  messages=[{"role": "user", "content": prompt}],
63
  model=self.config.model_name
 
67
  for line in raw_text.split('\n'):
68
  if ':' in line:
69
  speaker, _, content = line.partition(':')
70
+ if speaker.strip() in ("Anfitrión1", "Anfitrión2"):
71
  dialogue["conversation"].append({
72
  "speaker": speaker.strip(),
73
  "text": content.strip()
 
82
  try:
83
  for i, turn in enumerate(conversation_json["conversation"]):
84
  filename = output_dir / f"segment_{i}.mp3"
85
+ voice = voice_1 if turn["speaker"] == "Anfitrión1" else voice_2
86
  tmp_path = await self._generate_audio(turn["text"], voice)
87
  os.rename(tmp_path, filename)
88
  filenames.append(str(filename))
 
156
  return await self._process_to_audio(conversation, voice_1, voice_2)
157
 
158
  async def raw_text_to_audio(self, text: str, voice_1: str, voice_2: str) -> Tuple[str, str]:
159
+ conversation = {"conversation": [{"speaker": "Anfitrión1", "text": text}]}
160
  return await self._process_to_audio(conversation, voice_1, voice_2)
161
 
162
  async def _process_to_audio(
 
182
  f"{turn['speaker']}: {turn['text']}"
183
  for turn in conversation["conversation"]
184
  )
185
+ return output_path, text_output