app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoProcessor, AudioSpectrogramPipeline
|
3 |
+
import soundfile as sf
|
4 |
+
import tempfile
|
5 |
+
|
6 |
+
# โหลดโมเดลและ processor
|
7 |
+
processor = AutoProcessor.from_pretrained("stabilityai/stable-audio-open-small")
|
8 |
+
pipeline = AudioSpectrogramPipeline.from_pretrained("stabilityai/stable-audio-open-small")
|
9 |
+
|
10 |
+
def generate_audio(prompt):
|
11 |
+
result = pipeline(prompt=prompt, num_inference_steps=50)
|
12 |
+
audio = result["audio"]
|
13 |
+
sr = result["sampling_rate"]
|
14 |
+
|
15 |
+
# บันทึกไฟล์ชั่วคราวเพื่อให้ Gradio เล่นได้
|
16 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as f:
|
17 |
+
sf.write(f.name, audio, sr)
|
18 |
+
return f.name
|
19 |
+
|
20 |
+
# สร้าง UI
|
21 |
+
demo = gr.Interface(
|
22 |
+
fn=generate_audio,
|
23 |
+
inputs=gr.Textbox(label="Prompt (in English)", placeholder="e.g. A lo-fi beat with rain sounds"),
|
24 |
+
outputs=gr.Audio(label="Generated Audio"),
|
25 |
+
title="🎵 Stable Audio - Text to Sound",
|
26 |
+
description="Generate short sound clips from text using `stabilityai/stable-audio-open-small`"
|
27 |
+
)
|
28 |
+
|
29 |
+
demo.launch()
|