smgriffin's picture
more text generated
c1f3433
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
# Load the fine-tuned model and tokenizer from Hugging Face
model_name = "smgriffin/pop-lyrics-generator-v1" # Replace with your Hugging Face repo name
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
# Define the generation function
def generate_lyrics(artist):
prompt = f"Artist: {artist}\nLyrics:"
input_ids = tokenizer.encode(prompt, return_tensors="pt")
output = model.generate(
input_ids,
max_length=300, # Maximum number of tokens
temperature=0.9, # Adjust randomness
top_k=50, # Top-k sampling
top_p=0.95, # Nucleus sampling
do_sample=True, # Enable stochastic decoding
)
return tokenizer.decode(output[0], skip_special_tokens=True)
# List of artists for the dropdown
artists = [
"Coldplay", "Madonna", "The Beach Boys", "Barbra Streisand", "Michael Jackson", "Mariah Carey",
"Charli XCX", "Lana Del Rey", "Britney Spears", "Bjork", "Bee Gees", "Lady Gaga",
"Kenny Rogers", "Rihanna", "Justin Bieber", "Dua Lipa", "Judy Garland", "Ed Sheeran",
"Prince", "John Denver", "Elton John", "Meghan Trainor", "Katy Perry", "Demi Lovato",
"Enrique Iglesias", "Miley Cyrus", "Joni Mitchell", "David Guetta", "Beyonce",
"Avicii", "Backstreet Boys", "a-ha", "Sia", "Ellie Goulding", "Taylor Swift",
"Maroon 5", "Billie Eilish", "U2", "Shawn Mendes", "Carly Rae Jepsen", "Lil Wayne",
"Bob Dylan", "Sinad O'Connor", "Kenny Loggins", "Jimi Hendrix", "The Temptations",
"Jason Derulo", "Shakira", "Sabrina Carpenter", "Rick Astley", "Owl City",
"twenty one pilots", "Al Green", "Bruno Mars", "Chris Brown",
"Plain White T's", "5 Seconds of Summer", "John Lennon", "Olivia Rodrigo",
"3OH!3", "Jon Bellion", "Lorde", "Tate McRae", "Snoop Dogg", "Mike Posner",
"Selena Gomez & The Scene", "Drake", "Frank Ocean", "Tyler, The Creator",
"Camila Cabello", "Pharrell Williams", "The Beatles", "Chappell Roan",
"Kendrick Lamar", "SZA", "Post Malone", "Khalid", "Hozier", "The Weeknd",
"Ariana Grande", "Doja Cat", "Gracie Abrams", "Bad Bunny", "Usher"
]
artists = [
"Charli XCX","Coldplay", "Billie Eilish", "The Weeknd", "Rihanna", "Taylor Swift",
"Chappell Roan", "SZA", "Post Malone", "Khalid", "Hozier", "Lady Gaga", "Drake", "Ariana Grande", "Doja Cat", "Gracie Abrams", "Bad Bunny",
"Justin Bieber", "Dua Lipa", "Ed Sheeran",
"Meghan Trainor", "Katy Perry", "Demi Lovato", "Kendrick Lamar",
"Enrique Iglesias", "Miley Cyrus", "David Guetta", "Beyonce",
"Avicii", "a-ha", "Sia", "Ellie Goulding", "Usher",
"Maroon 5", "Shawn Mendes", "Carly Rae Jepsen", "Lil Wayne", "Britney Spears",
"Jason Derulo", "Shakira", "Sabrina Carpenter",
"twenty one pilots", "Bruno Mars", "Chris Brown",
"Plain White T's", "5 Seconds of Summer", "Olivia Rodrigo", "Lana Del Rey",
"3OH!3", "Jon Bellion", "Lorde", "Tate McRae", "Snoop Dogg", "Mike Posner",
"Selena Gomez & The Scene", "Frank Ocean", "Tyler, The Creator",
"Camila Cabello", "Pharrell Williams", "The Beatles",
"Michael Jackson", "Backstreet Boys","Jimi Hendrix", "Owl City", "John Lennon","The Temptations", "Kenny Loggins", "Al Green", "Sinad O'Connor", "U2", "Joni Mitchell", "Rick Astley","Bob Dylan", "Bjork","Elton John", "Prince", "Mariah Carey", "John Denver", "Bee Gees", "Kenny Rogers", "Judy Garland", "Madonna", "The Beach Boys", "Barbra Streisand"
]
# Define the Gradio interface
interface = gr.Interface(
fn=generate_lyrics,
inputs=gr.Dropdown(choices=artists, label="Select an Artist"),
outputs=gr.Textbox(label="Generated Lyrics"),
title="pop-lyrics-generator-v1-demo",
description="Select an artist from the dropdown and click 'Submit' to generate lyrics based on their style.",
)
# Launch the app
interface.launch()