smgriffin commited on
Commit
63026af
·
1 Parent(s): a628971

Add application file

Browse files
Files changed (2) hide show
  1. app.py +53 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+
4
+ # Load the fine-tuned model and tokenizer from Hugging Face
5
+ model_name = "smgriffin/pop-lyrics-generator-v1" # Replace with your Hugging Face repo name
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
+
9
+ # Define the generation function
10
+ def generate_lyrics(artist):
11
+ prompt = f"Artist: {artist}\nLyrics:"
12
+ input_ids = tokenizer.encode(prompt, return_tensors="pt")
13
+ output = model.generate(
14
+ input_ids,
15
+ max_length=150, # Maximum number of tokens
16
+ temperature=0.9, # Adjust randomness
17
+ top_k=50, # Top-k sampling
18
+ top_p=0.95, # Nucleus sampling
19
+ do_sample=True, # Enable stochastic decoding
20
+ )
21
+ return tokenizer.decode(output[0], skip_special_tokens=True)
22
+
23
+ # List of artists for the dropdown
24
+ artists = [
25
+ "Madonna", "The Beach Boys", "Barbra Streisand", "Michael Jackson", "Mariah Carey",
26
+ "Charli XCX", "Lana Del Rey", "Britney Spears", "Bjork", "Bee Gees", "Lady Gaga",
27
+ "Kenny Rogers", "Rihanna", "Justin Bieber", "Dua Lipa", "Judy Garland", "Ed Sheeran",
28
+ "Prince", "John Denver", "Elton John", "Meghan Trainor", "Katy Perry", "Demi Lovato",
29
+ "Enrique Iglesias", "Miley Cyrus", "Joni Mitchell", "David Guetta", "Beyonce",
30
+ "Avicii", "Backstreet Boys", "a-ha", "Sia", "Ellie Goulding", "Taylor Swift",
31
+ "Maroon 5", "Billie Eilish", "U2", "Shawn Mendes", "Carly Rae Jepsen", "Lil Wayne",
32
+ "Bob Dylan", "Sinad O'Connor", "Kenny Loggins", "Jimi Hendrix", "The Temptations",
33
+ "Jason Derulo", "Shakira", "Sabrina Carpenter", "Rick Astley", "Owl City",
34
+ "twenty one pilots", "Al Green", "Coldplay", "Bruno Mars", "Chris Brown",
35
+ "Plain White T's", "5 Seconds of Summer", "John Lennon", "Olivia Rodrigo",
36
+ "3OH!3", "Jon Bellion", "Lorde", "Tate McRae", "Snoop Dogg", "Mike Posner",
37
+ "Selena Gomez & The Scene", "Drake", "Frank Ocean", "Tyler, The Creator",
38
+ "Camila Cabello", "Pharrell Williams", "The Beatles", "Chappell Roan",
39
+ "Kendrick Lamar", "SZA", "Post Malone", "Khalid", "Hozier", "The Weeknd",
40
+ "Ariana Grande", "Doja Cat", "Gracie Abrams", "Bad Bunny", "Usher"
41
+ ]
42
+
43
+ # Define the Gradio interface
44
+ interface = gr.Interface(
45
+ fn=generate_lyrics,
46
+ inputs=gr.Dropdown(choices=artists, label="Select an Artist"),
47
+ outputs=gr.Textbox(label="Generated Lyrics"),
48
+ title="Lyrics Generator",
49
+ description="Select an artist from the dropdown and click 'Submit' to generate lyrics based on their style.",
50
+ )
51
+
52
+ # Launch the app
53
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch