Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,21 @@
|
|
| 1 |
-
import torch
|
| 2 |
import gradio as gr
|
| 3 |
-
from transformers import
|
| 4 |
-
import scipy
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
processor = AutoProcessor.from_pretrained("facebook/musicgen-stereo-32khz")
|
| 9 |
|
| 10 |
-
def
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
audio_array = audio_values[0].cpu().numpy()
|
| 14 |
-
sample_rate = model.config.audio_encoder.sampling_rate
|
| 15 |
|
| 16 |
-
|
| 17 |
-
output_path = "generated_music.wav"
|
| 18 |
-
scipy.io.wavfile.write(output_path, sample_rate, audio_array.T)
|
| 19 |
-
return output_path
|
| 20 |
-
|
| 21 |
-
# Gradio UI
|
| 22 |
iface = gr.Interface(
|
| 23 |
-
fn=
|
| 24 |
-
inputs=gr.Textbox(label="Enter
|
| 25 |
-
outputs=gr.Audio(label="Generated
|
| 26 |
-
title="
|
| 27 |
-
description="
|
| 28 |
)
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
-
iface.launch()
|
| 32 |
-
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
+
# Load the text-to-audio model
|
| 5 |
+
tts = pipeline("text-to-audio", model="facebook/musicgen-small")
|
|
|
|
| 6 |
|
| 7 |
+
def text_to_audio(text):
|
| 8 |
+
output = tts(text)
|
| 9 |
+
return output["audio"]
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Create Gradio interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
iface = gr.Interface(
|
| 13 |
+
fn=text_to_audio,
|
| 14 |
+
inputs=gr.Textbox(label="Enter Text"),
|
| 15 |
+
outputs=gr.Audio(label="Generated Audio"),
|
| 16 |
+
title="Text-to-Audio Chatbot",
|
| 17 |
+
description="Enter text, and get an AI-generated audio response."
|
| 18 |
)
|
| 19 |
|
| 20 |
if __name__ == "__main__":
|
| 21 |
+
iface.launch()
|
|
|