Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -35,26 +35,30 @@ def generate_script(user_prompt: str, model_id: str, token: str, duration: int):
|
|
35 |
llama_pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
36 |
|
37 |
system_prompt = (
|
38 |
-
|
39 |
-
|
40 |
-
f"
|
|
|
|
|
41 |
)
|
42 |
|
43 |
combined_prompt = f"{system_prompt}\nUser concept: {user_prompt}\nRefined script and music suggestion:"
|
44 |
result = llama_pipeline(combined_prompt, max_new_tokens=500, do_sample=True, temperature=0.9)
|
45 |
|
46 |
-
#
|
47 |
generated_text = result[0]["generated_text"]
|
48 |
-
if "
|
49 |
-
parts = generated_text.split("
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
55 |
except Exception as e:
|
56 |
return f"Error generating script: {e}", None
|
57 |
|
|
|
58 |
# ---------------------------------------------------------------------
|
59 |
# Voice-Over Generation Function
|
60 |
# ---------------------------------------------------------------------
|
|
|
35 |
llama_pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
36 |
|
37 |
system_prompt = (
|
38 |
+
"You are an expert radio imaging producer specializing in sound design and music.\n"
|
39 |
+
"---\n"
|
40 |
+
f"Based on the user's concept and the selected duration of {duration} seconds, craft a concise, engaging promo script.\n"
|
41 |
+
"---\n"
|
42 |
+
"Ensure the script fits within the time limit and suggest a matching music style that complements the theme."
|
43 |
)
|
44 |
|
45 |
combined_prompt = f"{system_prompt}\nUser concept: {user_prompt}\nRefined script and music suggestion:"
|
46 |
result = llama_pipeline(combined_prompt, max_new_tokens=500, do_sample=True, temperature=0.9)
|
47 |
|
48 |
+
# Parsing the output
|
49 |
generated_text = result[0]["generated_text"]
|
50 |
+
if "Refined script and music suggestion:" in generated_text:
|
51 |
+
parts = generated_text.split("Refined script and music suggestion:", 1)[-1].strip()
|
52 |
+
if "Music Style:" in parts:
|
53 |
+
script, music_suggestion = parts.split("Music Style:", 1)
|
54 |
+
return script.strip(), music_suggestion.strip()
|
55 |
+
else:
|
56 |
+
return parts.strip(), "No specific music suggestion found."
|
57 |
+
return "Error: Could not parse the script.", None
|
58 |
except Exception as e:
|
59 |
return f"Error generating script: {e}", None
|
60 |
|
61 |
+
|
62 |
# ---------------------------------------------------------------------
|
63 |
# Voice-Over Generation Function
|
64 |
# ---------------------------------------------------------------------
|