Spaces:
Running
Running
uploading essentials
Browse files- app.py +29 -0
- requirements.txt +0 -0
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from streamlit.elements.altair import generate_chart
|
3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
4 |
+
from transformers import pipeline
|
5 |
+
st.title("Rap Lyrics Generator")
|
6 |
+
#st.image('./parental.png')
|
7 |
+
|
8 |
+
model_ckpt = "flax-community/gpt2-rap-lyric-generator"
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_ckpt,from_flax=True)
|
10 |
+
model = AutoModelForCausalLM.from_pretrained(model_ckpt,from_flax=True)
|
11 |
+
text_generation = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
12 |
+
|
13 |
+
artist = st.text_input("Enter the artist", "Eminem")
|
14 |
+
song_name = st.text_input("Enter the desired song name", "Gas is going")
|
15 |
+
|
16 |
+
if st.button("Generate lyrics"):
|
17 |
+
st.title(f"{artist}: {song_name}")
|
18 |
+
prefix_text = f"<BOS>{song_name} [Verse 1:{artist}]"
|
19 |
+
generated_song = text_generation(prefix_text, max_length=500, do_sample=True)[0]
|
20 |
+
for count, line in enumerate(generated_song['generated_text'].split("\n")):
|
21 |
+
if count == 0:
|
22 |
+
st.write(line[line.find('['):])
|
23 |
+
continue
|
24 |
+
if"<EOS>" in line:
|
25 |
+
break
|
26 |
+
if "<BOS>" in line:
|
27 |
+
st.write(line[5:])
|
28 |
+
continue
|
29 |
+
st.write(line)
|
requirements.txt
ADDED
File without changes
|