Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,7 +25,7 @@ musicgen_processor = None
|
|
| 25 |
# ---------------------------------------------------------------------
|
| 26 |
# Load Llama 3 Model with Zero GPU (Lazy Loading)
|
| 27 |
# ---------------------------------------------------------------------
|
| 28 |
-
@spaces.GPU(duration=300)
|
| 29 |
def load_llama_pipeline_zero_gpu(model_id: str, token: str):
|
| 30 |
global llama_pipeline
|
| 31 |
if llama_pipeline is None:
|
|
@@ -101,38 +101,25 @@ def generate_audio(prompt: str, audio_length: int):
|
|
| 101 |
# ---------------------------------------------------------------------
|
| 102 |
# Gradio Interface
|
| 103 |
# ---------------------------------------------------------------------
|
| 104 |
-
def radio_imaging_app(user_prompt, llama_model_id
|
| 105 |
# Load Llama 3 Pipeline with Zero GPU
|
| 106 |
pipeline_llama = load_llama_pipeline_zero_gpu(llama_model_id, hf_token)
|
| 107 |
if isinstance(pipeline_llama, str):
|
| 108 |
-
return pipeline_llama
|
| 109 |
|
| 110 |
# Generate Script
|
| 111 |
-
|
|
|
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
return script, audio_data
|
| 116 |
|
| 117 |
|
| 118 |
# ---------------------------------------------------------------------
|
| 119 |
# Interface
|
| 120 |
# ---------------------------------------------------------------------
|
| 121 |
-
with gr.Blocks(
|
| 122 |
-
#
|
| 123 |
-
text-align: center;
|
| 124 |
-
font-size: 2rem;
|
| 125 |
-
font-weight: bold;
|
| 126 |
-
color: #4CAF50;
|
| 127 |
-
}
|
| 128 |
-
#subsection {
|
| 129 |
-
margin: 20px 0;
|
| 130 |
-
font-size: 1.2rem;
|
| 131 |
-
color: #333;
|
| 132 |
-
text-align: center;
|
| 133 |
-
}
|
| 134 |
-
""") as demo:
|
| 135 |
-
gr.Markdown('<div id="app-title">🎧 AI Radio Imaging with Llama 3 + MusicGen (Zero GPU)</div>')
|
| 136 |
|
| 137 |
with gr.Tab("Step 1: Generate Promo Script"):
|
| 138 |
with gr.Row():
|
|
@@ -149,8 +136,8 @@ with gr.Blocks(css="""
|
|
| 149 |
|
| 150 |
generate_script_button.click(
|
| 151 |
fn=radio_imaging_app,
|
| 152 |
-
inputs=[user_prompt, llama_model_id
|
| 153 |
-
outputs=
|
| 154 |
)
|
| 155 |
|
| 156 |
with gr.Tab("Step 2: Generate Audio"):
|
|
@@ -166,7 +153,7 @@ with gr.Blocks(css="""
|
|
| 166 |
audio_output = gr.Audio(label="Generated Audio", type="filepath")
|
| 167 |
|
| 168 |
generate_audio_button.click(
|
| 169 |
-
fn=
|
| 170 |
inputs=[script_output, audio_length],
|
| 171 |
outputs=audio_output,
|
| 172 |
)
|
|
|
|
| 25 |
# ---------------------------------------------------------------------
|
| 26 |
# Load Llama 3 Model with Zero GPU (Lazy Loading)
|
| 27 |
# ---------------------------------------------------------------------
|
| 28 |
+
@spaces.GPU(duration=300)
|
| 29 |
def load_llama_pipeline_zero_gpu(model_id: str, token: str):
|
| 30 |
global llama_pipeline
|
| 31 |
if llama_pipeline is None:
|
|
|
|
| 101 |
# ---------------------------------------------------------------------
|
| 102 |
# Gradio Interface
|
| 103 |
# ---------------------------------------------------------------------
|
| 104 |
+
def radio_imaging_app(user_prompt, llama_model_id):
|
| 105 |
# Load Llama 3 Pipeline with Zero GPU
|
| 106 |
pipeline_llama = load_llama_pipeline_zero_gpu(llama_model_id, hf_token)
|
| 107 |
if isinstance(pipeline_llama, str):
|
| 108 |
+
return pipeline_llama
|
| 109 |
|
| 110 |
# Generate Script
|
| 111 |
+
return generate_script(user_prompt, pipeline_llama)
|
| 112 |
+
|
| 113 |
|
| 114 |
+
def generate_audio_from_script(script, audio_length):
|
| 115 |
+
return generate_audio(script, audio_length)
|
|
|
|
| 116 |
|
| 117 |
|
| 118 |
# ---------------------------------------------------------------------
|
| 119 |
# Interface
|
| 120 |
# ---------------------------------------------------------------------
|
| 121 |
+
with gr.Blocks() as demo:
|
| 122 |
+
gr.Markdown("# 🎧 AI Radio Imaging with Llama 3 + MusicGen (Zero GPU)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
with gr.Tab("Step 1: Generate Promo Script"):
|
| 125 |
with gr.Row():
|
|
|
|
| 136 |
|
| 137 |
generate_script_button.click(
|
| 138 |
fn=radio_imaging_app,
|
| 139 |
+
inputs=[user_prompt, llama_model_id],
|
| 140 |
+
outputs=script_output,
|
| 141 |
)
|
| 142 |
|
| 143 |
with gr.Tab("Step 2: Generate Audio"):
|
|
|
|
| 153 |
audio_output = gr.Audio(label="Generated Audio", type="filepath")
|
| 154 |
|
| 155 |
generate_audio_button.click(
|
| 156 |
+
fn=generate_audio_from_script,
|
| 157 |
inputs=[script_output, audio_length],
|
| 158 |
outputs=audio_output,
|
| 159 |
)
|