Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,17 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
import soundfile as sf
|
5 |
|
6 |
+
model_name = "facebook/musicgen-small"
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
|
10 |
+
def text_to_audio(prompt):
|
11 |
+
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
|
12 |
+
output = model.generate(input_ids)
|
13 |
+
audio_data = output[0].cpu().numpy()
|
14 |
+
sf.write("generated_audio.wav", audio_data, 22050)
|
15 |
+
return "generated_audio.wav"
|
16 |
+
|
17 |
+
gr.Interface(fn=text_to_audio, inputs="text", outputs="audio").launch()
|