Bils commited on
Commit
fd8d42a
·
verified ·
1 Parent(s): 3172dc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
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, generate: "
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
- if "Suggestions:" in generated_text and "Music Recommendations:" in generated_text:
52
- script, rest = generated_text.split("Suggestions:", 1)
53
- sound_design, music_suggestion = rest.split("Music Recommendations:", 1)
54
- return script.strip(), sound_design.strip(), music_suggestion.strip()
55
- return "Error: Could not parse output.", "", ""
 
 
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