Spaces:
Runtime error
Runtime error
done
Browse files
app.py
CHANGED
|
@@ -1,87 +1,3 @@
|
|
| 1 |
-
# import torch
|
| 2 |
-
# import torchaudio
|
| 3 |
-
# from einops import rearrange
|
| 4 |
-
# import gradio as gr
|
| 5 |
-
# import spaces
|
| 6 |
-
# import os
|
| 7 |
-
# import uuid
|
| 8 |
-
|
| 9 |
-
# # Importing the model-related functions
|
| 10 |
-
# from stable_audio_tools import get_pretrained_model
|
| 11 |
-
# from stable_audio_tools.inference.generation import generate_diffusion_cond
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
# from huggingface_hub import login
|
| 15 |
-
|
| 16 |
-
# hf_token = os.getenv('HF_TOKEN')
|
| 17 |
-
# login(token=hf_token,add_to_git_credential=True)
|
| 18 |
-
|
| 19 |
-
# # Load the model outside of the GPU-decorated function
|
| 20 |
-
# def load_model():
|
| 21 |
-
# print("Loading model...")
|
| 22 |
-
# model, model_config = get_pretrained_model("stabilityai/stable-audio-open-1.0")
|
| 23 |
-
# print("Model loaded successfully.")
|
| 24 |
-
# return model, model_config
|
| 25 |
-
|
| 26 |
-
# # Define the function to generate audio
|
| 27 |
-
# @spaces.GPU(duration=120)
|
| 28 |
-
# def generate_audio(prompt, bpm, seconds_total):
|
| 29 |
-
# device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 30 |
-
|
| 31 |
-
# # Download model
|
| 32 |
-
# model, model_config = load_model()
|
| 33 |
-
# sample_rate = model_config["sample_rate"]
|
| 34 |
-
# sample_size = model_config["sample_size"]
|
| 35 |
-
|
| 36 |
-
# model = model.to(device)
|
| 37 |
-
|
| 38 |
-
# # Set up text and timing conditioning
|
| 39 |
-
# conditioning = [{
|
| 40 |
-
# "prompt": f"{bpm} BPM {prompt}",
|
| 41 |
-
# "seconds_start": 0,
|
| 42 |
-
# "seconds_total": seconds_total
|
| 43 |
-
# }]
|
| 44 |
-
|
| 45 |
-
# # Generate stereo audio
|
| 46 |
-
# output = generate_diffusion_cond(
|
| 47 |
-
# model,
|
| 48 |
-
# steps=100,
|
| 49 |
-
# cfg_scale=7,
|
| 50 |
-
# conditioning=conditioning,
|
| 51 |
-
# sample_size=sample_size,
|
| 52 |
-
# sigma_min=0.3,
|
| 53 |
-
# sigma_max=500,
|
| 54 |
-
# sampler_type="dpmpp-3m-sde",
|
| 55 |
-
# device=device
|
| 56 |
-
# )
|
| 57 |
-
|
| 58 |
-
# # Rearrange audio batch to a single sequence
|
| 59 |
-
# output = rearrange(output, "b d n -> d (b n)")
|
| 60 |
-
|
| 61 |
-
# # Peak normalize, clip, convert to int16, and save to file
|
| 62 |
-
# output = output.to(torch.float32).div(torch.max(torch.abs(output))).clamp(-1, 1).mul(32767).to(torch.int16).cpu()
|
| 63 |
-
|
| 64 |
-
# output_path = "output.wav"
|
| 65 |
-
# torchaudio.save(output_path, output, sample_rate)
|
| 66 |
-
|
| 67 |
-
# return output_path
|
| 68 |
-
|
| 69 |
-
# # Define the Gradio interface
|
| 70 |
-
# iface = gr.Interface(
|
| 71 |
-
# fn=generate_audio,
|
| 72 |
-
# inputs=[
|
| 73 |
-
# gr.Textbox(label="Prompt", placeholder="Enter the description of the audio (e.g., tech house drum loop)"),
|
| 74 |
-
# gr.Number(label="BPM", value=128),
|
| 75 |
-
# gr.Number(label="Duration (seconds)", value=30)
|
| 76 |
-
# ],
|
| 77 |
-
# outputs=gr.Audio(label="Generated Audio"),
|
| 78 |
-
# title="Stable Audio Generation",
|
| 79 |
-
# description="Generate audio based on a text prompt using stable audio tools.",
|
| 80 |
-
# )
|
| 81 |
-
|
| 82 |
-
# # Launch the interface
|
| 83 |
-
# iface.launch()
|
| 84 |
-
|
| 85 |
import torch
|
| 86 |
import torchaudio
|
| 87 |
from einops import rearrange
|
|
@@ -96,9 +12,9 @@ from stable_audio_tools.inference.generation import generate_diffusion_cond
|
|
| 96 |
|
| 97 |
# Load the model outside of the GPU-decorated function
|
| 98 |
def load_model():
|
| 99 |
-
|
| 100 |
model, model_config = get_pretrained_model("stabilityai/stable-audio-open-1.0")
|
| 101 |
-
print("
|
| 102 |
return model, model_config
|
| 103 |
|
| 104 |
# Function to set up, generate, and process the audio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import torchaudio
|
| 3 |
from einops import rearrange
|
|
|
|
| 12 |
|
| 13 |
# Load the model outside of the GPU-decorated function
|
| 14 |
def load_model():
|
| 15 |
+
|
| 16 |
model, model_config = get_pretrained_model("stabilityai/stable-audio-open-1.0")
|
| 17 |
+
print("Loading model...Done")
|
| 18 |
return model, model_config
|
| 19 |
|
| 20 |
# Function to set up, generate, and process the audio
|