Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Initialize the text-to-audio pipeline with the MusicGen small model
|
| 5 |
+
pipe = pipeline("text-to-audio", model="facebook/musicgen-small")
|
| 6 |
+
|
| 7 |
+
# Define the function to generate audio from text
|
| 8 |
+
def generate_audio(text):
|
| 9 |
+
audio_output = pipe(text)
|
| 10 |
+
return audio_output["audio"]
|
| 11 |
+
|
| 12 |
+
# Set up the Gradio interface using updated components
|
| 13 |
+
app = gr.Interface(
|
| 14 |
+
fn=generate_audio, # Function to call for text-to-audio generation
|
| 15 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter text to generate audio"), # Updated input field for text
|
| 16 |
+
outputs=gr.Audio(type="numpy"), # Updated output for audio
|
| 17 |
+
title="Text to Audio Generator", # Title of the app
|
| 18 |
+
description="Generate music or audio from text using Facebook's MusicGen small model."
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# Launch the app
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
app.launch()
|