Master0fNone commited on
Commit
5c7d782
·
verified ·
1 Parent(s): fb77ecd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import torch
4
+ import soundfile as sf
5
+
6
+ # Load your pre-trained text-to-music model (example: using a music generation model)
7
+ model = pipeline("text-to-music", model="facebook/musicge-small")
8
+
9
+ # Function to process text and generate music
10
+ def generate_music(text_input):
11
+ # This part depends on the model you use
12
+ music_output = model(text_input) # Generate music based on input text
13
+
14
+ # Save the music to a file or return it directly
15
+ output_file = "/path/to/output.wav"
16
+ sf.write(output_file, music_output, 22050) # Example: Saving at 22050 Hz sample rate
17
+ return output_file
18
+
19
+ # Set up the Gradio interface
20
+ iface = gr.Interface(
21
+ fn=generate_music,
22
+ inputs=gr.Textbox(label="Enter Text for Music"),
23
+ outputs=gr.Audio(label="Generated Music")
24
+ )
25
+
26
+ # Launch the app
27
+ iface.launch()