Spaces:
Runtime error
Runtime error
Commit
·
a8a7e8c
1
Parent(s):
94c5cd8
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,24 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import torch
|
3 |
-
from transformers import MusicLM
|
4 |
|
5 |
-
model
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
def
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
12 |
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelWithLMHead, AutoTokenizer
|
3 |
import torch
|
|
|
4 |
|
5 |
+
# Load the model and tokenizer
|
6 |
+
model_name = "Gertie01/MusicLM"
|
7 |
+
model = AutoModelWithLMHead.from_pretrained(model_name)
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
|
10 |
+
# Define the function to generate music
|
11 |
+
def generate_music(text):
|
12 |
+
input_ids = tokenizer.encode(text, return_tensors="pt")
|
13 |
+
output = model.generate(input_ids, max_length=100)
|
14 |
+
generated_music = tokenizer.decode(output[0], skip_special_tokens=True)
|
15 |
+
return generated_music
|
16 |
|
17 |
+
# Create the Gradio interface
|
18 |
+
input_text = gr.inputs.Textbox(lines=5, label="Input Text")
|
19 |
+
output_text = gr.outputs.Textbox(label="Generated Music")
|
20 |
+
|
21 |
+
title = "Music Generation with GPT-3.5"
|
22 |
+
description = "Enter a text prompt and the model will generate music based on it."
|
23 |
+
|
24 |
+
gr.Interface(fn=generate_music, inputs=input_text, outputs=output_text, title=title, description=description).launch()
|