Spaces:
Runtime error
Runtime error
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -319,45 +319,27 @@ def generate_script(
|
|
| 319 |
min_words = max(50, numeric_minutes * 100)
|
| 320 |
|
| 321 |
max_words = numeric_minutes * words_per_minute
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
# Tone mapping dictionary
|
| 333 |
-
|
| 334 |
-
tone_map={
|
| 335 |
-
"Humorous":"funny and exciting,makes people chuckle",
|
| 336 |
-
"Formal":"business-like,wells-structured,"professional",
|
| 337 |
-
"Casual":"like a conversation between close friends,"relaxed and informal",
|
| 338 |
-
"Youthful":"like how teenagers might chat,"energetic and lively"
|
| 339 |
-
}
|
| 340 |
|
| 341 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
|
| 343 |
# Determine sponsor instructions based on sponsor_provided and sponsor_style
|
| 344 |
-
|
| 345 |
if sponsor_provided:
|
| 346 |
|
| 347 |
-
if sponsor_style=="Separate Break":
|
| 348 |
-
sponsor_instructions=(
|
| 349 |
-
|
| 350 |
-
"If sponsor content is provided,"include it in a separate ad break (~30 seconds). "
|
| 351 |
-
|
| 352 |
"Use phrasing like 'Now a word from our sponsor...' and end with 'Back to the show' or similar."
|
| 353 |
)
|
| 354 |
|
| 355 |
else:
|
| 356 |
|
| 357 |
-
sponsor_instructions=(
|
| 358 |
-
|
| 359 |
-
"If sponsor content is provided,"blend it naturally (~30 seconds) into the conversation."
|
| 360 |
-
|
| 361 |
"Avoid abrupt transitions."
|
| 362 |
)
|
| 363 |
|
|
@@ -365,7 +347,6 @@ else:
|
|
| 365 |
|
| 366 |
sponsor_instructions="" # No sponsor instructions if sponsor_provided is empty
|
| 367 |
|
| 368 |
-
|
| 369 |
prompt=(
|
| 370 |
|
| 371 |
f"{system_prompt}\n"
|
|
@@ -405,7 +386,6 @@ f"# Sponsor Style Instruction:\n{sponsor_instructions}\n\n"
|
|
| 405 |
"}"
|
| 406 |
)
|
| 407 |
|
| 408 |
-
|
| 409 |
print("[LOG] Sending prompt to Groq:")
|
| 410 |
print(prompt)
|
| 411 |
|
|
@@ -606,4 +586,10 @@ if response.status_code!=200:
|
|
| 606 |
|
| 607 |
raise ValueError(f"Deepgram TTS error:{response.status_code},{response.text}")
|
| 608 |
|
| 609 |
-
content_type=response.headers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
min_words = max(50, numeric_minutes * 100)
|
| 320 |
|
| 321 |
max_words = numeric_minutes * words_per_minute
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
|
| 323 |
+
tone_map = {
|
| 324 |
+
"Humorous": "funny and exciting, makes people chuckle",
|
| 325 |
+
"Formal": "business-like, well-structured, professional",
|
| 326 |
+
"Casual": "like a conversation between close friends, relaxed and informal",
|
| 327 |
+
"Youthful": "like how teenagers might chat, energetic and lively"
|
| 328 |
+
}
|
| 329 |
|
| 330 |
# Determine sponsor instructions based on sponsor_provided and sponsor_style
|
|
|
|
| 331 |
if sponsor_provided:
|
| 332 |
|
| 333 |
+
if sponsor_style == "Separate Break":
|
| 334 |
+
sponsor_instructions = (
|
| 335 |
+
"If sponsor content is provided, include it in a separate ad break (~30 seconds). "
|
|
|
|
|
|
|
| 336 |
"Use phrasing like 'Now a word from our sponsor...' and end with 'Back to the show' or similar."
|
| 337 |
)
|
| 338 |
|
| 339 |
else:
|
| 340 |
|
| 341 |
+
sponsor_instructions = (
|
| 342 |
+
"If sponsor content is provided, blend it naturally (~30 seconds) into the conversation. "
|
|
|
|
|
|
|
| 343 |
"Avoid abrupt transitions."
|
| 344 |
)
|
| 345 |
|
|
|
|
| 347 |
|
| 348 |
sponsor_instructions="" # No sponsor instructions if sponsor_provided is empty
|
| 349 |
|
|
|
|
| 350 |
prompt=(
|
| 351 |
|
| 352 |
f"{system_prompt}\n"
|
|
|
|
| 386 |
"}"
|
| 387 |
)
|
| 388 |
|
|
|
|
| 389 |
print("[LOG] Sending prompt to Groq:")
|
| 390 |
print(prompt)
|
| 391 |
|
|
|
|
| 586 |
|
| 587 |
raise ValueError(f"Deepgram TTS error:{response.status_code},{response.text}")
|
| 588 |
|
| 589 |
+
content_type=response.headers.get('Content-Type','')
|
| 590 |
+
|
| 591 |
+
if 'audio/mpeg' not in content_type:
|
| 592 |
+
|
| 593 |
+
raise ValueError("Unexpected Content-Type from Deepgram.")
|
| 594 |
+
|
| 595 |
+
with tempfile.NamedTemporaryFile(delete=False,suffix=".mp3
|