gnosticdev commited on
Commit
a2a2610
·
verified ·
1 Parent(s): 97cd35a

Update conver.py

Browse files
Files changed (1) hide show
  1. conver.py +21 -13
conver.py CHANGED
@@ -56,21 +56,29 @@ class URLToAudioConverter:
56
  if not text:
57
  raise ValueError("Input text cannot be empty")
58
  try:
59
- 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..."
 
 
 
 
 
 
 
60
  response = self.llm_client.chat.completions.create(
61
  messages=[{"role": "user", "content": prompt}],
62
- model=self.config.model_name
 
63
  )
64
- raw_text = response.choices[0].message.content
65
- dialogue = {"conversation": []}
66
- for line in raw_text.split('\n'):
67
- if ':' in line:
68
- speaker, _, content = line.partition(':')
69
- if speaker.strip() in ("Anfitrión1", "Anfitrión2"):
70
- dialogue["conversation"].append({
71
- "speaker": speaker.strip(),
72
- "text": content.strip()
73
- })
74
  return dialogue
75
  except Exception as e:
76
  raise RuntimeError(f"Failed to parse dialogue: {str(e)}")
@@ -186,4 +194,4 @@ class URLToAudioConverter:
186
  f"{turn['speaker']}: {turn['text']}"
187
  for turn in conversation["conversation"]
188
  )
189
- return output_path, text_output
 
56
  if not text:
57
  raise ValueError("Input text cannot be empty")
58
  try:
59
+ prompt = (
60
+ f"{text}\nConvierte el texto proporcionado en un diálogo de podcast en español "
61
+ f"entre Anfitrión1 y Anfitrión2. Genera una conversación extensa, detallada y natural, "
62
+ f"como en un podcast real, con al menos 5 intercambios por hablante. "
63
+ f"Devuelve SOLO un objeto JSON con la siguiente estructura:\n"
64
+ '{"conversation": [{"speaker": "Anfitrión1", "text": "..."}, {"speaker": "Anfitrión2", "text": "..."}]}'
65
+ )
66
+ print(f"Texto de entrada: {text[:200]}...") # Depuración
67
  response = self.llm_client.chat.completions.create(
68
  messages=[{"role": "user", "content": prompt}],
69
+ model=self.config.model_name,
70
+ response_format={"type": "json_object"}
71
  )
72
+ response_content = response.choices[0].message.content
73
+ print(f"Respuesta cruda del modelo: {response_content[:500]}...") # Depuración
74
+ json_str = response_content.strip()
75
+ if not json_str.startswith('{'):
76
+ json_str = json_str[json_str.find('{'):]
77
+ if not json_str.endswith('}'):
78
+ json_str = json_str[:json_str.rfind('}')+1]
79
+ dialogue = json.loads(json_str)
80
+ if not dialogue.get("conversation"):
81
+ print("Error: No se generó diálogo válido.")
82
  return dialogue
83
  except Exception as e:
84
  raise RuntimeError(f"Failed to parse dialogue: {str(e)}")
 
194
  f"{turn['speaker']}: {turn['text']}"
195
  for turn in conversation["conversation"]
196
  )
197
+ return output_path, text_output