rajarr commited on
Commit
8d340e2
·
verified ·
1 Parent(s): 04cce06

app.py created.

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import torch
3
+ import gradio as gr
4
+ from diffusers import StableAudioPipeline
5
+
6
+ # Initialize pipeline
7
+ pipe = StableAudioPipeline.from_pretrained(
8
+ "stabilityai/stable-audio-open-1.0",
9
+ torch_dtype=torch.float16
10
+ )
11
+
12
+ @spaces.GPU(duration=60) # Allocates GPU dynamically when run
13
+ def generate_audio(prompt, negative_prompt, seconds):
14
+ pipe.to("cuda")
15
+ output = pipe(
16
+ prompt=prompt,
17
+ negative_prompt=negative_prompt,
18
+ audio_end_in_s=seconds,
19
+ num_inference_steps=100,
20
+ )
21
+ return (44100, output.audios[0].T.cpu().numpy())
22
+
23
+ # Gradio Interface setup
24
+ demo = gr.Interface(
25
+ fn=generate_audio,
26
+ inputs=[
27
+ gr.Textbox(label="Audio Prompt"),
28
+ gr.Textbox(label="Negative Prompt", value="low quality, noise, distortion"),
29
+ gr.Slider(minimum=5, maximum=47, value=15, label="Duration (Seconds)")
30
+ ],
31
+ outputs=gr.Audio(label="Generated SFX"),
32
+ title="My Custom Stable Audio Studio"
33
+ )
34
+
35
+ demo.launch()