stardate69
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -18,29 +18,34 @@ login(HUGGINGFACE_TOKEN)
|
|
18 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
19 |
torch_dtype = torch.float16 if device == "cuda" else torch.float32
|
20 |
|
21 |
-
# Load the StableAudio model from Hugging Face Hub
|
22 |
-
pipe = StableAudioPipeline.from_pretrained("stabilityai/stable-audio-open-1.0", torch_dtype=torch_dtype)
|
23 |
-
pipe = pipe.to(device)
|
24 |
|
25 |
# Initialize Flask app
|
26 |
app = Flask(__name__)
|
27 |
|
28 |
# Route to generate audio
|
29 |
-
|
30 |
@app.route("/generate", methods=["GET"])
|
31 |
@spaces.GPU
|
32 |
def generate_audio():
|
|
|
33 |
prompt = request.args.get("prompt")
|
34 |
seed = request.args.get("seed", random.randint(0, 100000), type=int)
|
|
|
35 |
if not prompt:
|
36 |
return jsonify({"error": "Missing prompt parameter"}), 400
|
37 |
|
38 |
try:
|
|
|
|
|
|
|
|
|
|
|
39 |
# Generate the audio using StableAudioPipeline
|
40 |
-
generator = torch.Generator(device)
|
|
|
|
|
41 |
audio_output = pipe(
|
42 |
prompt=prompt,
|
43 |
-
negative_prompt='',
|
44 |
num_inference_steps=10, # Number of diffusion steps
|
45 |
guidance_scale=3.0,
|
46 |
audio_end_in_s=1,
|
|
|
18 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
19 |
torch_dtype = torch.float16 if device == "cuda" else torch.float32
|
20 |
|
|
|
|
|
|
|
21 |
|
22 |
# Initialize Flask app
|
23 |
app = Flask(__name__)
|
24 |
|
25 |
# Route to generate audio
|
|
|
26 |
@app.route("/generate", methods=["GET"])
|
27 |
@spaces.GPU
|
28 |
def generate_audio():
|
29 |
+
|
30 |
prompt = request.args.get("prompt")
|
31 |
seed = request.args.get("seed", random.randint(0, 100000), type=int)
|
32 |
+
|
33 |
if not prompt:
|
34 |
return jsonify({"error": "Missing prompt parameter"}), 400
|
35 |
|
36 |
try:
|
37 |
+
|
38 |
+
# Load the StableAudio model from Hugging Face Hub
|
39 |
+
pipe = StableAudioPipeline.from_pretrained("stabilityai/stable-audio-open-1.0", torch_dtype=torch_dtype)
|
40 |
+
pipe = pipe.to(device)
|
41 |
+
|
42 |
# Generate the audio using StableAudioPipeline
|
43 |
+
generator = torch.Generator(device)
|
44 |
+
generator.manual_seed(seed)
|
45 |
+
|
46 |
audio_output = pipe(
|
47 |
prompt=prompt,
|
48 |
+
negative_prompt='Low Quality',
|
49 |
num_inference_steps=10, # Number of diffusion steps
|
50 |
guidance_scale=3.0,
|
51 |
audio_end_in_s=1,
|