Spaces:
Runtime error
Runtime error
generate audio minor refactor 2
Browse files
app.py
CHANGED
|
@@ -172,22 +172,22 @@ def generate_audio(prompt: str, duration: int) -> gr.Component:
|
|
| 172 |
Returns:
|
| 173 |
gr.Component: The generated audio as a Gradio Audio component.
|
| 174 |
"""
|
| 175 |
-
|
| 176 |
DURATION_LIMIT = 30
|
| 177 |
-
|
|
|
|
| 178 |
client = Tool.from_space(
|
| 179 |
space_id="luke9705/MusicGen_custom",
|
| 180 |
token=os.environ.get('HF_TOKEN'),
|
| 181 |
name="Sound_Generator",
|
| 182 |
description="Generate music or sound effects from a text prompt using MusicGen."
|
| 183 |
)
|
| 184 |
-
|
| 185 |
-
duration = duration if duration < DURATION_LIMIT else DURATION_LIMIT
|
| 186 |
|
| 187 |
sound = client(prompt, duration)
|
| 188 |
|
| 189 |
return gr.Audio(value=sound)
|
| 190 |
|
|
|
|
| 191 |
@tool
|
| 192 |
def generate_audio_from_sample(prompt: str, duration: int, sample_path: str = None) -> gr.Component:
|
| 193 |
"""
|
|
@@ -196,21 +196,22 @@ def generate_audio_from_sample(prompt: str, duration: int, sample_path: str = No
|
|
| 196 |
prompt: The text prompt to generate the audio from.
|
| 197 |
duration: Duration of the generated audio in seconds. Max 30 seconds.
|
| 198 |
sample_path: audio sample path to guide generation.
|
| 199 |
-
|
| 200 |
Returns:
|
| 201 |
gr.Component: The generated audio as a Gradio Audio component.
|
| 202 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
client = Tool.from_space(
|
| 204 |
space_id="luke9705/MusicGen_custom",
|
| 205 |
token=os.environ.get('HF_TOKEN'),
|
| 206 |
name="Sound_Generator",
|
| 207 |
description="Generate music or sound effects from a text prompt using MusicGen."
|
| 208 |
)
|
| 209 |
-
if duration > 30:
|
| 210 |
-
sound = client(prompt, 30, sample_path)
|
| 211 |
-
else:
|
| 212 |
-
sound = client(prompt, duration, sample_path)
|
| 213 |
|
|
|
|
|
|
|
| 214 |
return gr.Audio(value=sound)
|
| 215 |
|
| 216 |
@tool
|
|
|
|
| 172 |
Returns:
|
| 173 |
gr.Component: The generated audio as a Gradio Audio component.
|
| 174 |
"""
|
| 175 |
+
|
| 176 |
DURATION_LIMIT = 30
|
| 177 |
+
duration = duration if duration < DURATION_LIMIT else DURATION_LIMIT
|
| 178 |
+
|
| 179 |
client = Tool.from_space(
|
| 180 |
space_id="luke9705/MusicGen_custom",
|
| 181 |
token=os.environ.get('HF_TOKEN'),
|
| 182 |
name="Sound_Generator",
|
| 183 |
description="Generate music or sound effects from a text prompt using MusicGen."
|
| 184 |
)
|
|
|
|
|
|
|
| 185 |
|
| 186 |
sound = client(prompt, duration)
|
| 187 |
|
| 188 |
return gr.Audio(value=sound)
|
| 189 |
|
| 190 |
+
|
| 191 |
@tool
|
| 192 |
def generate_audio_from_sample(prompt: str, duration: int, sample_path: str = None) -> gr.Component:
|
| 193 |
"""
|
|
|
|
| 196 |
prompt: The text prompt to generate the audio from.
|
| 197 |
duration: Duration of the generated audio in seconds. Max 30 seconds.
|
| 198 |
sample_path: audio sample path to guide generation.
|
|
|
|
| 199 |
Returns:
|
| 200 |
gr.Component: The generated audio as a Gradio Audio component.
|
| 201 |
"""
|
| 202 |
+
|
| 203 |
+
DURATION_LIMIT = 30
|
| 204 |
+
duration = duration if duration < DURATION_LIMIT else DURATION_LIMIT
|
| 205 |
+
|
| 206 |
client = Tool.from_space(
|
| 207 |
space_id="luke9705/MusicGen_custom",
|
| 208 |
token=os.environ.get('HF_TOKEN'),
|
| 209 |
name="Sound_Generator",
|
| 210 |
description="Generate music or sound effects from a text prompt using MusicGen."
|
| 211 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
+
sound = client(prompt, duration, sample_path)
|
| 214 |
+
|
| 215 |
return gr.Audio(value=sound)
|
| 216 |
|
| 217 |
@tool
|