Bils commited on
Commit
1a0bb5e
·
verified ·
1 Parent(s): 8b6a33e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -26
app.py CHANGED
@@ -109,20 +109,18 @@ def generate_audio(prompt: str, audio_length: int):
109
  # ---------------------------------------------------------------------
110
  # Gradio Interface
111
  # ---------------------------------------------------------------------
112
- def radio_imaging_script(user_prompt, llama_model_id):
113
  # Load Llama 3 Pipeline with Zero GPU
114
  pipeline_llama = load_llama_pipeline_zero_gpu(llama_model_id, hf_token)
115
  if isinstance(pipeline_llama, str):
116
- return pipeline_llama
117
 
118
  # Generate Script
119
  script = generate_script(user_prompt, pipeline_llama)
120
- return script
121
 
122
- def radio_imaging_audio(script, audio_length):
123
  # Generate Audio
124
  audio_data = generate_audio(script, audio_length)
125
- return audio_data
126
 
127
  # ---------------------------------------------------------------------
128
  # Interface
@@ -130,31 +128,20 @@ def radio_imaging_audio(script, audio_length):
130
  with gr.Blocks() as demo:
131
  gr.Markdown("# 🎧 AI Radio Imaging with Llama 3 + MusicGen (Zero GPU)")
132
 
133
- # Script Generation Section
134
  with gr.Row():
135
- gr.Markdown("## Step 1: Generate the Promo Script")
136
  user_prompt = gr.Textbox(label="Enter your promo idea", placeholder="E.g., A 15-second hype jingle for a morning talk show.")
137
  llama_model_id = gr.Textbox(label="Llama 3 Model ID", value="meta-llama/Meta-Llama-3-70B")
138
- generate_script_button = gr.Button("Generate Promo Script")
139
- script_output = gr.Textbox(label="Generated Script", interactive=False)
140
-
141
- generate_script_button.click(
142
- fn=radio_imaging_script,
143
- inputs=[user_prompt, llama_model_id],
144
- outputs=script_output
145
- )
146
-
147
- # Audio Generation Section
148
- with gr.Row():
149
- gr.Markdown("## Step 2: Generate the Sound")
150
  audio_length = gr.Slider(label="Audio Length (tokens)", minimum=128, maximum=1024, step=64, value=512)
151
- generate_audio_button = gr.Button("Generate Sound from Script")
152
- audio_output = gr.Audio(label="Generated Audio", type="filepath")
153
 
154
- generate_audio_button.click(
155
- fn=radio_imaging_audio,
156
- inputs=[script_output, audio_length],
157
- outputs=audio_output
158
- )
 
 
159
 
 
 
 
160
  demo.launch(debug=True)
 
109
  # ---------------------------------------------------------------------
110
  # Gradio Interface
111
  # ---------------------------------------------------------------------
112
+ def radio_imaging_app(user_prompt, llama_model_id, audio_length):
113
  # Load Llama 3 Pipeline with Zero GPU
114
  pipeline_llama = load_llama_pipeline_zero_gpu(llama_model_id, hf_token)
115
  if isinstance(pipeline_llama, str):
116
+ return pipeline_llama, None
117
 
118
  # Generate Script
119
  script = generate_script(user_prompt, pipeline_llama)
 
120
 
 
121
  # Generate Audio
122
  audio_data = generate_audio(script, audio_length)
123
+ return script, audio_data
124
 
125
  # ---------------------------------------------------------------------
126
  # Interface
 
128
  with gr.Blocks() as demo:
129
  gr.Markdown("# 🎧 AI Radio Imaging with Llama 3 + MusicGen (Zero GPU)")
130
 
 
131
  with gr.Row():
 
132
  user_prompt = gr.Textbox(label="Enter your promo idea", placeholder="E.g., A 15-second hype jingle for a morning talk show.")
133
  llama_model_id = gr.Textbox(label="Llama 3 Model ID", value="meta-llama/Meta-Llama-3-70B")
 
 
 
 
 
 
 
 
 
 
 
 
134
  audio_length = gr.Slider(label="Audio Length (tokens)", minimum=128, maximum=1024, step=64, value=512)
 
 
135
 
136
+ generate_button = gr.Button("Generate Promo Script and Audio")
137
+ script_output = gr.Textbox(label="Generated Script")
138
+ audio_output = gr.Audio(label="Generated Audio", type="filepath")
139
+
140
+ generate_button.click(radio_imaging_app,
141
+ inputs=[user_prompt, llama_model_id, audio_length],
142
+ outputs=[script_output, audio_output])
143
 
144
+ # ---------------------------------------------------------------------
145
+ # Launch App
146
+ # ---------------------------------------------------------------------
147
  demo.launch(debug=True)