cazyundee commited on
Commit
9dccb71
·
verified ·
1 Parent(s): 6b31614

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +33 -9
  2. app.py +77 -0
  3. requirements.txt +7 -0
README.md CHANGED
@@ -1,15 +1,39 @@
1
  ---
2
- title: Stable Audio 3.0 API
3
- emoji:
4
- colorFrom: gray
5
- colorTo: gray
6
  sdk: gradio
7
- sdk_version: 6.22.0
8
- python_version: '3.12'
9
  app_file: app.py
10
  pinned: false
11
- license: mit
12
- short_description: api
13
  ---
14
 
15
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Stable Audio 3 Small
3
+ emoji: 🎵
4
+ colorFrom: purple
5
+ colorTo: blue
6
  sdk: gradio
7
+ sdk_version: 6.3.0
 
8
  app_file: app.py
9
  pinned: false
 
 
10
  ---
11
 
12
+ # Stable Audio 3 Small - Music Generation
13
+
14
+ A CPU-based Hugging Face Space for generating music using [Stability AI's Stable Audio 3](https://github.com/Stability-AI/stable-audio-3) Small model.
15
+
16
+ ## Features
17
+
18
+ - **Model**: `small-music` (433M parameters)
19
+ - **Duration**: 1–120 seconds
20
+ - **Sample rate**: 44.1 kHz stereo
21
+ - **Runs on CPU** (no GPU required)
22
+ - Gradio 6.3.0 interface
23
+
24
+ ## Usage
25
+
26
+ 1. Enter a text prompt describing the music you want
27
+ 2. Adjust duration, steps, CFG scale, and seed
28
+ 3. Click **Generate** and wait for the audio
29
+
30
+ ## Setup
31
+
32
+ ```bash
33
+ pip install -r requirements.txt
34
+ python app.py
35
+ ```
36
+
37
+ ## License
38
+
39
+ This project uses the Stable Audio 3 model. Please refer to Stability AI's [license](https://huggingface.co/stabilityai/stable-audio-3-small) for usage terms.
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import torch
3
+ import torchaudio
4
+ import gradio as gr
5
+ from einops import rearrange
6
+ from stable_audio_3 import StableAudioModel
7
+
8
+ # Load model once at startup
9
+ print("Loading Stable Audio 3 Small model...")
10
+ model = StableAudioModel.from_pretrained("small-music", device="cpu")
11
+ print("Model loaded successfully!")
12
+
13
+
14
+ def generate_audio(prompt, duration, steps, cfg_scale, seed):
15
+ print(f"Generating: prompt='{prompt}', duration={duration}s, steps={steps}, cfg={cfg_scale}, seed={seed}")
16
+
17
+ audio = model.generate(
18
+ prompt=prompt,
19
+ duration=duration,
20
+ steps=steps,
21
+ cfg_scale=cfg_scale,
22
+ seed=seed,
23
+ batch_size=1
24
+ )
25
+
26
+ # Post-process: (batch, channels, samples) -> stereo waveform
27
+ audio = rearrange(audio, "b d n -> d (b n)")
28
+ audio = audio.to(torch.float32).clamp(-1, 1).mul(32767).to(torch.int16).cpu()
29
+
30
+ output_path = "output.wav"
31
+ torchaudio.save(output_path, audio, 44100)
32
+ print("Generation complete!")
33
+ return output_path
34
+
35
+
36
+ with gr.Blocks(title="Stable Audio 3 Small") as demo:
37
+ gr.Markdown("# 🎵 Stable Audio 3 Small - Music Generation")
38
+ gr.Markdown("Generate music using Stability AI's Stable Audio 3 Small model. Runs on CPU.")
39
+
40
+ with gr.Row():
41
+ with gr.Column():
42
+ prompt = gr.Textbox(
43
+ label="Prompt",
44
+ placeholder="Describe the music you want to generate...",
45
+ lines=2
46
+ )
47
+ duration = gr.Slider(
48
+ minimum=1, maximum=120, value=30, step=1,
49
+ label="Duration (seconds)"
50
+ )
51
+ steps = gr.Slider(
52
+ minimum=1, maximum=50, value=8, step=1,
53
+ label="Steps"
54
+ )
55
+ cfg_scale = gr.Slider(
56
+ minimum=0.0, maximum=10.0, value=1.0, step=0.1,
57
+ label="CFG Scale"
58
+ )
59
+ seed = gr.Number(
60
+ value=-1, label="Seed (-1 for random)"
61
+ )
62
+ btn = gr.Button("Generate", variant="primary")
63
+
64
+ with gr.Column():
65
+ audio_output = gr.Audio(
66
+ label="Generated Audio",
67
+ type="filepath"
68
+ )
69
+
70
+ btn.click(
71
+ fn=generate_audio,
72
+ inputs=[prompt, duration, steps, cfg_scale, seed],
73
+ outputs=audio_output
74
+ )
75
+
76
+
77
+ demo.queue(max_size=4, default_concurrency_limit=1).launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ stable-audio-3[ui]
2
+ gradio==6.3.0
3
+ soundfile>=0.13.1
4
+ einops
5
+ torch>=2.7.1
6
+ torchaudio>=2.7.1
7
+ huggingface-hub>=1.7.1