Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import torch
|
| 2 |
-
from transformers import
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
# Load the model and tokenizer from Hugging Face
|
|
@@ -10,19 +10,23 @@ tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
| 10 |
model = AutoModel.from_pretrained(model_name, ignore_mismatched_sizes=True)
|
| 11 |
|
| 12 |
# Define a function for Gradio that uses the model to generate music
|
| 13 |
-
def generate_music(prompt):
|
| 14 |
-
|
|
|
|
| 15 |
outputs = model(**inputs)
|
| 16 |
return "Generated instrumental music or lyrics" # Replace with actual music processing
|
| 17 |
|
| 18 |
# Set up Gradio interface
|
| 19 |
interface = gr.Interface(
|
| 20 |
fn=generate_music,
|
| 21 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
| 22 |
outputs="text",
|
| 23 |
title="Jukebox Music Generator",
|
| 24 |
-
description="Enter a prompt to generate instrumental music using the Jukebox 1B Lyrics model."
|
| 25 |
)
|
| 26 |
|
| 27 |
-
# Launch the interface
|
| 28 |
-
interface.launch()
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from transformers import AutoTokenizer, AutoModel
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
# Load the model and tokenizer from Hugging Face
|
|
|
|
| 10 |
model = AutoModel.from_pretrained(model_name, ignore_mismatched_sizes=True)
|
| 11 |
|
| 12 |
# Define a function for Gradio that uses the model to generate music
|
| 13 |
+
def generate_music(prompt, genre):
|
| 14 |
+
# Tokenize input with the specified genre
|
| 15 |
+
inputs = tokenizer(prompt, genres=genre, return_tensors="pt")
|
| 16 |
outputs = model(**inputs)
|
| 17 |
return "Generated instrumental music or lyrics" # Replace with actual music processing
|
| 18 |
|
| 19 |
# Set up Gradio interface
|
| 20 |
interface = gr.Interface(
|
| 21 |
fn=generate_music,
|
| 22 |
+
inputs=[
|
| 23 |
+
gr.inputs.Textbox(label="Prompt"),
|
| 24 |
+
gr.inputs.Textbox(label="Genre") # Adding genre as input
|
| 25 |
+
],
|
| 26 |
outputs="text",
|
| 27 |
title="Jukebox Music Generator",
|
| 28 |
+
description="Enter a prompt and genre to generate instrumental music using the Jukebox 1B Lyrics model."
|
| 29 |
)
|
| 30 |
|
| 31 |
+
# Launch the interface with share=True for a public link
|
| 32 |
+
interface.launch(share=True)
|