Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,23 +36,27 @@ def generate_script(user_prompt: str, model_id: str, token: str, duration: int):
|
|
| 36 |
)
|
| 37 |
llama_pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 38 |
|
|
|
|
| 39 |
system_prompt = (
|
| 40 |
f"You are an expert radio imaging producer specializing in sound design and music. "
|
| 41 |
-
f"Based on the user's concept and the selected duration of {duration} seconds,
|
| 42 |
-
f"1. A concise voice-over script. "
|
| 43 |
-
f"2. Suggestions for sound design. "
|
| 44 |
-
f"3. Music styles or track recommendations."
|
| 45 |
)
|
| 46 |
|
| 47 |
combined_prompt = f"{system_prompt}\nUser concept: {user_prompt}\nOutput:"
|
| 48 |
result = llama_pipeline(combined_prompt, max_new_tokens=300, do_sample=True, temperature=0.8)
|
| 49 |
|
|
|
|
| 50 |
generated_text = result[0]["generated_text"].split("Output:")[-1].strip()
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
| 56 |
except Exception as e:
|
| 57 |
return f"Error generating script: {e}", "", ""
|
| 58 |
|
|
|
|
| 36 |
)
|
| 37 |
llama_pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 38 |
|
| 39 |
+
# System prompt with clear structure instructions
|
| 40 |
system_prompt = (
|
| 41 |
f"You are an expert radio imaging producer specializing in sound design and music. "
|
| 42 |
+
f"Based on the user's concept and the selected duration of {duration} seconds, produce the following: "
|
| 43 |
+
f"1. A concise voice-over script. Prefix this section with 'Voice-Over Script:'.\n"
|
| 44 |
+
f"2. Suggestions for sound design. Prefix this section with 'Sound Design Suggestions:'.\n"
|
| 45 |
+
f"3. Music styles or track recommendations. Prefix this section with 'Music Suggestions:'."
|
| 46 |
)
|
| 47 |
|
| 48 |
combined_prompt = f"{system_prompt}\nUser concept: {user_prompt}\nOutput:"
|
| 49 |
result = llama_pipeline(combined_prompt, max_new_tokens=300, do_sample=True, temperature=0.8)
|
| 50 |
|
| 51 |
+
# Parsing output
|
| 52 |
generated_text = result[0]["generated_text"].split("Output:")[-1].strip()
|
| 53 |
+
|
| 54 |
+
# Extract sections based on prefixes
|
| 55 |
+
voice_script = generated_text.split("Voice-Over Script:")[1].split("Sound Design Suggestions:")[0].strip() if "Voice-Over Script:" in generated_text else "No voice-over script found."
|
| 56 |
+
sound_design = generated_text.split("Sound Design Suggestions:")[1].split("Music Suggestions:")[0].strip() if "Sound Design Suggestions:" in generated_text else "No sound design suggestions found."
|
| 57 |
+
music_suggestions = generated_text.split("Music Suggestions:")[1].strip() if "Music Suggestions:" in generated_text else "No music suggestions found."
|
| 58 |
+
|
| 59 |
+
return voice_script, sound_design, music_suggestions
|
| 60 |
except Exception as e:
|
| 61 |
return f"Error generating script: {e}", "", ""
|
| 62 |
|