Spaces:
Running
Running
Update conver.py
Browse files
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 =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
response = self.llm_client.chat.completions.create(
|
61 |
messages=[{"role": "user", "content": prompt}],
|
62 |
-
model=self.config.model_name
|
|
|
63 |
)
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
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
|