Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from diffusers import AudioLDMPipeline
|
| 4 |
+
|
| 5 |
+
print("Loading AudioLDM Model (This takes a few minutes on boot)...")
|
| 6 |
+
# Using the small model to fit in the free tier RAM
|
| 7 |
+
repo_id = "cvssp/audioldm-s-full-v2"
|
| 8 |
+
pipe = AudioLDMPipeline.from_pretrained(repo_id, torch_dtype=torch.float32)
|
| 9 |
+
|
| 10 |
+
def generate_audio(text_prompt, duration, guidance):
|
| 11 |
+
print(f"Generating sound for: {text_prompt}")
|
| 12 |
+
# Number of inference steps reduced slightly for faster CPU generation
|
| 13 |
+
audio = pipe(
|
| 14 |
+
text_prompt,
|
| 15 |
+
num_inference_steps=15,
|
| 16 |
+
audio_length_in_s=duration,
|
| 17 |
+
guidance_scale=guidance
|
| 18 |
+
).audios[0]
|
| 19 |
+
|
| 20 |
+
# Diffusers outputs audio at 16000Hz sampling rate
|
| 21 |
+
return (16000, audio)
|
| 22 |
+
|
| 23 |
+
with gr.Blocks(theme=gr.themes.Monochrome()) as app:
|
| 24 |
+
gr.Markdown("# 🎬 The Foley Artist AI")
|
| 25 |
+
gr.Markdown("Generate high-fidelity sound effects from text descriptions.")
|
| 26 |
+
|
| 27 |
+
with gr.Row():
|
| 28 |
+
with gr.Column():
|
| 29 |
+
prompt = gr.Textbox(label="Describe the Sound (e.g., 'Footsteps on gravel')", lines=2)
|
| 30 |
+
duration = gr.Slider(minimum=2.5, maximum=5.0, value=2.5, step=2.5, label="Duration (Seconds)")
|
| 31 |
+
guidance = gr.Slider(minimum=1.0, maximum=5.0, value=2.5, step=0.5, label="Guidance Scale (Higher = closer to text)")
|
| 32 |
+
generate_btn = gr.Button("Generate Audio", variant="primary")
|
| 33 |
+
|
| 34 |
+
with gr.Column():
|
| 35 |
+
audio_output = gr.Audio(label="Generated Sound Effect")
|
| 36 |
+
|
| 37 |
+
generate_btn.click(
|
| 38 |
+
generate_audio,
|
| 39 |
+
inputs=[prompt, duration, guidance],
|
| 40 |
+
outputs=[audio_output]
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
app.launch()
|