Spaces:
Running
Running
Update conver.py
Browse files
conver.py
CHANGED
@@ -14,7 +14,7 @@ from threading import Thread
|
|
14 |
|
15 |
@dataclass
|
16 |
class ConversationConfig:
|
17 |
-
max_words: int =
|
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
|
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 ("
|
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"] == "
|
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": "
|
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
|