Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -192,6 +192,15 @@ class PodcastGenerator:
|
|
| 192 |
|
| 193 |
add_log("⚠️ No valid JSON found, creating fallback")
|
| 194 |
return self.create_fallback_podcast(text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
def validate_podcast_structure(self, data: Dict) -> bool:
|
| 197 |
"""Validate podcast JSON structure"""
|
|
@@ -302,7 +311,7 @@ class PodcastGenerator:
|
|
| 302 |
language_instruction = f"Generate in {language}" if language != "Auto Detect" else "Use appropriate language"
|
| 303 |
|
| 304 |
# Simplified and more reliable prompt
|
| 305 |
-
system_prompt = f"""Create a podcast script
|
| 306 |
|
| 307 |
Requirements:
|
| 308 |
- Exactly 2 speakers (speaker 1 and 2)
|
|
@@ -311,7 +320,11 @@ Requirements:
|
|
| 311 |
- DO NOT copy the example below , only use it as conversation reference
|
| 312 |
- The podcast should be professional, in-depth, lively, witty and engaging, and hook the listener from the start.
|
| 313 |
- The input text might be disorganized or unformatted. Ignore any formatting inconsistencies or irrelevant details; your task is to distill the essential points, identify key definitions, and highlight intriguing facts that would be suitable for discussion in a podcast.
|
| 314 |
-
- The
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
- {language_instruction}
|
| 316 |
"""
|
| 317 |
|
|
@@ -338,7 +351,7 @@ Requirements:
|
|
| 338 |
)
|
| 339 |
|
| 340 |
# Move to correct device
|
| 341 |
-
inputs = {k: v.to(self.model.device) for k, v in inputs.items()}
|
| 342 |
add_log(f"✅ Inputs moved to device: {self.model.device}")
|
| 343 |
|
| 344 |
add_log("🧠 Generating with model...")
|
|
@@ -371,7 +384,8 @@ Requirements:
|
|
| 371 |
progress(0.4, "🔍 Processing generated script...")
|
| 372 |
|
| 373 |
# Extract and validate JSON
|
| 374 |
-
result = self.clean_and_validate_json(generated_text)
|
|
|
|
| 375 |
|
| 376 |
if progress:
|
| 377 |
progress(0.5, "✅ Script generated successfully!")
|
|
|
|
| 192 |
|
| 193 |
add_log("⚠️ No valid JSON found, creating fallback")
|
| 194 |
return self.create_fallback_podcast(text)
|
| 195 |
+
|
| 196 |
+
def conversation_to_json(text: str) -> Dict:
|
| 197 |
+
"""Convert speaker-formatted text to podcast JSON structure"""
|
| 198 |
+
lines = re.findall(r'(Speaker\s[12]):\s*(.+)', text)
|
| 199 |
+
podcast = [{"speaker": int(s[-1]), "line": l.strip()} for s, l in lines]
|
| 200 |
+
return {
|
| 201 |
+
"topic": "Generated from PDF",
|
| 202 |
+
"podcast": podcast
|
| 203 |
+
}
|
| 204 |
|
| 205 |
def validate_podcast_structure(self, data: Dict) -> bool:
|
| 206 |
"""Validate podcast JSON structure"""
|
|
|
|
| 311 |
language_instruction = f"Generate in {language}" if language != "Auto Detect" else "Use appropriate language"
|
| 312 |
|
| 313 |
# Simplified and more reliable prompt
|
| 314 |
+
system_prompt = f"""Create a podcast script
|
| 315 |
|
| 316 |
Requirements:
|
| 317 |
- Exactly 2 speakers (speaker 1 and 2)
|
|
|
|
| 320 |
- DO NOT copy the example below , only use it as conversation reference
|
| 321 |
- The podcast should be professional, in-depth, lively, witty and engaging, and hook the listener from the start.
|
| 322 |
- The input text might be disorganized or unformatted. Ignore any formatting inconsistencies or irrelevant details; your task is to distill the essential points, identify key definitions, and highlight intriguing facts that would be suitable for discussion in a podcast.
|
| 323 |
+
- The two-person conversation must be in following format, always leading with the speaker ID
|
| 324 |
+
Speaker 1: Hello to our podcast
|
| 325 |
+
Speaker 2: ...
|
| 326 |
+
Speaker 1: ...
|
| 327 |
+
Speaker 2: ...
|
| 328 |
- {language_instruction}
|
| 329 |
"""
|
| 330 |
|
|
|
|
| 351 |
)
|
| 352 |
|
| 353 |
# Move to correct device
|
| 354 |
+
#inputs = {k: v.to(self.model.device) for k, v in inputs.items()}
|
| 355 |
add_log(f"✅ Inputs moved to device: {self.model.device}")
|
| 356 |
|
| 357 |
add_log("🧠 Generating with model...")
|
|
|
|
| 384 |
progress(0.4, "🔍 Processing generated script...")
|
| 385 |
|
| 386 |
# Extract and validate JSON
|
| 387 |
+
#result = self.clean_and_validate_json(generated_text)
|
| 388 |
+
result = conversation_to_json(generated_text)
|
| 389 |
|
| 390 |
if progress:
|
| 391 |
progress(0.5, "✅ Script generated successfully!")
|