File size: 880 Bytes
19555f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
from transformers import pipeline

# Initialize the text-to-audio pipeline with the MusicGen small model
pipe = pipeline("text-to-audio", model="facebook/musicgen-small")

# Define the function to generate audio from text
def generate_audio(text):
    audio_output = pipe(text)
    return audio_output["audio"]

# Set up the Gradio interface using updated components
app = gr.Interface(
    fn=generate_audio,                # Function to call for text-to-audio generation
    inputs=gr.Textbox(lines=2, placeholder="Enter text to generate audio"),  # Updated input field for text
    outputs=gr.Audio(type="numpy"),    # Updated output for audio
    title="Text to Audio Generator",   # Title of the app
    description="Generate music or audio from text using Facebook's MusicGen small model."
)

# Launch the app
if __name__ == "__main__":
    app.launch()