File size: 1,854 Bytes
2e07021
 
2193261
 
 
 
 
 
2e07021
3c69c2b
7e79b1c
2193261
 
 
2e07021
3c69c2b
2193261
b14b378
 
 
 
2e07021
3c69c2b
2193261
 
 
 
b14b378
2193261
 
 
 
 
 
 
 
 
 
 
3c69c2b
b14b378
3c69c2b
aa89711
3c69c2b
aa89711
 
3c69c2b
 
 
 
aa89711
3c69c2b
1c7efde
3c69c2b
 
 
b14b378
3c69c2b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
from huggingface_hub import login
import torch
import torchaudio
from einops import rearrange
import gradio as gr
from stable_audio_tools import get_pretrained_model
from stable_audio_tools.inference.generation import generate_diffusion_cond

# Authenticate
token = os.getenv("HUGGINGFACE_TOKEN")
if not token:
    raise RuntimeError("HUGGINGFACE_TOKEN not set")
login(token=token, add_to_git_credential=False)

# Load model
device = "cuda" if torch.cuda.is_available() else "cpu"
model, config = get_pretrained_model("stabilityai/stable-audio-open-small")
model = model.to(device)
sample_rate = config["sample_rate"]
sample_size = config["sample_size"]

# Inference function
def generate_audio(prompt):
    conditioning = [{"prompt": prompt, "seconds_total": 11}]
    with torch.no_grad():
        output = generate_diffusion_cond(
            model,
            steps=8,
            conditioning=conditioning,
            sample_size=sample_size,
            device=device
        )
    output = rearrange(output, "b d n -> d (b n)")
    output = output.to(torch.float32).div(torch.max(torch.abs(output))).clamp(-1, 1).mul(32767).to(torch.int16).cpu()
    path = "output.wav"
    torchaudio.save(path, output, sample_rate)
    return path

# πŸŒ€ Hot Prompt Club UI
gr.Interface(
    fn=generate_audio,
    inputs=gr.Textbox(
        label="🎀 Prompt your sonic art here",
        placeholder="e.g. 'drunk driving with mario and yung lean'"
    ),
    outputs=gr.Audio(
        type="filepath",
        label="🧠 Generated Audio"
    ),
    title='🌐 Hot Prompts in Your Area: "My Husband Is Dead"',
    description="Enter a fun sound idea for music art.",
    examples=[
        "ghosts peeing in a server room",
        "tech startup boss villain entrance music",
        "AI doing acid in a technofeudalist dystopia"
    ]
).launch()