Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,9 @@
|
|
| 1 |
import os
|
| 2 |
from huggingface_hub import login
|
| 3 |
-
import torch
|
| 4 |
-
import torchaudio
|
| 5 |
-
from einops import rearrange
|
| 6 |
-
import gradio as gr
|
| 7 |
-
from stable_audio_tools import get_pretrained_model
|
| 8 |
-
from stable_audio_tools.inference.generation import generate_diffusion_cond
|
| 9 |
|
| 10 |
-
|
| 11 |
-
login(token=os.getenv("HUGGINGFACE_TOKEN"), add_to_git_credential=False)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
model = model.to(device)
|
| 16 |
-
sample_rate = config["sample_rate"]
|
| 17 |
-
sample_size = config["sample_size"]
|
| 18 |
|
| 19 |
-
|
| 20 |
-
conditioning = [{"prompt": prompt, "seconds_total": 11}]
|
| 21 |
-
with torch.no_grad():
|
| 22 |
-
output = generate_diffusion_cond(
|
| 23 |
-
model,
|
| 24 |
-
steps=8,
|
| 25 |
-
conditioning=conditioning,
|
| 26 |
-
sample_size=sample_size,
|
| 27 |
-
device=device
|
| 28 |
-
)
|
| 29 |
-
output = rearrange(output, "b d n -> d (b n)")
|
| 30 |
-
output = output.to(torch.float32).div(torch.max(torch.abs(output))).clamp(-1, 1).mul(32767).to(torch.int16).cpu()
|
| 31 |
-
path = "output.wav"
|
| 32 |
-
torchaudio.save(path, output, sample_rate)
|
| 33 |
-
return path
|
| 34 |
-
|
| 35 |
-
gr.Interface(
|
| 36 |
-
fn=generate_audio,
|
| 37 |
-
inputs=gr.Textbox(label="Enter your sound prompt"),
|
| 38 |
-
outputs=gr.Audio(type="filepath"),
|
| 39 |
-
title="Stable Audio Generator"
|
| 40 |
-
).launch()
|
|
|
|
| 1 |
import os
|
| 2 |
from huggingface_hub import login
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
token = os.getenv("HUGGINGFACE_TOKEN")
|
|
|
|
| 5 |
|
| 6 |
+
if token is None or token == "":
|
| 7 |
+
raise RuntimeError("HUGGINGFACE_TOKEN is not set or is empty.")
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
login(token=token, add_to_git_credential=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|