Bils commited on
Commit
c64dd82
·
verified ·
1 Parent(s): 1fc5d0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
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
- f"You are an expert radio imaging producer specializing in sound design and music. "
39
- f"Based on the user's concept and the selected duration of {duration} seconds, craft a concise, engaging promo script. "
40
- f"Ensure the script fits within the time limit and suggest a matching music style that complements the theme."
 
 
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
- # Extract the script and music suggestion
47
  generated_text = result[0]["generated_text"]
48
- if "Music:" in generated_text:
49
- parts = generated_text.split("Music:", 1)
50
- script = parts[0].strip()
51
- music_suggestion = parts[1].strip()
52
- return script, music_suggestion
53
- else:
54
- return generated_text.strip(), "No specific music suggestion found."
 
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
  # ---------------------------------------------------------------------