rajarr commited on
Commit
ff7b1c4
·
verified ·
1 Parent(s): 57177f7

Hf Token update

Browse files
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -1,41 +1,37 @@
 
1
  import spaces
2
  import torch
3
  import gradio as gr
4
  from diffusers import StableAudioPipeline
5
 
6
- # 1. Load pipeline on CPU first (ZeroGPU pattern)
7
  pipe = StableAudioPipeline.from_pretrained(
8
  "stabilityai/stable-audio-open-1.0",
9
- torch_dtype=torch.float16
 
10
  )
11
 
12
- # 2. Decorate the execution function with @spaces.GPU
13
  @spaces.GPU(duration=60)
14
  def generate_audio(prompt, negative_prompt, seconds):
15
- # Move to GPU dynamically when invoked
16
  pipe.to("cuda")
17
-
18
  output = pipe(
19
  prompt=prompt,
20
  negative_prompt=negative_prompt,
21
  audio_end_in_s=seconds,
22
  num_inference_steps=100,
23
  )
24
-
25
- # Format output for Gradio (Sample Rate, Audio Array)
26
  audio_data = output.audios[0].T.cpu().numpy()
27
  return (44100, audio_data)
28
 
29
- # 3. Launch Gradio UI
30
  demo = gr.Interface(
31
  fn=generate_audio,
32
  inputs=[
33
- gr.Textbox(label="Prompt", value="128 BPM tech house drum loop with heavy kick and sub bass"),
34
- gr.Textbox(label="Negative Prompt", value="low quality, noise, distortion"),
35
  gr.Slider(minimum=5, maximum=47, value=15, label="Duration (Seconds)")
36
  ],
37
- outputs=gr.Audio(label="Generated Audio"),
38
- title="Stable Audio Open Generator"
39
  )
40
 
41
  demo.launch()
 
1
+ import os
2
  import spaces
3
  import torch
4
  import gradio as gr
5
  from diffusers import StableAudioPipeline
6
 
7
+ # Load model passing token=True to authenticate
8
  pipe = StableAudioPipeline.from_pretrained(
9
  "stabilityai/stable-audio-open-1.0",
10
+ torch_dtype=torch.float16,
11
+ token=True # <--- Reads HF_TOKEN secret automatically
12
  )
13
 
 
14
  @spaces.GPU(duration=60)
15
  def generate_audio(prompt, negative_prompt, seconds):
 
16
  pipe.to("cuda")
 
17
  output = pipe(
18
  prompt=prompt,
19
  negative_prompt=negative_prompt,
20
  audio_end_in_s=seconds,
21
  num_inference_steps=100,
22
  )
 
 
23
  audio_data = output.audios[0].T.cpu().numpy()
24
  return (44100, audio_data)
25
 
 
26
  demo = gr.Interface(
27
  fn=generate_audio,
28
  inputs=[
29
+ gr.Textbox(label="Prompt", value="Heavy metal door slam in an echoing dungeon"),
30
+ gr.Textbox(label="Negative Prompt", value="low quality, distortion"),
31
  gr.Slider(minimum=5, maximum=47, value=15, label="Duration (Seconds)")
32
  ],
33
+ outputs=gr.Audio(label="Generated SFX"),
34
+ title="Stable Audio Studio"
35
  )
36
 
37
  demo.launch()