Spaces:
Running
Running
File size: 1,253 Bytes
9d46201 4ab88cc bfd1de9 4ab88cc 292ac90 bfd1de9 9d46201 292ac90 2620132 4cd22cd 9d46201 183cde3 0502abd 9d46201 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import streamlit as st
from streamlit.elements.altair import generate_chart
from transformers import AutoTokenizer, AutoModelForCausalLM
from transformers import pipeline
@st.cache
def load_model():
model_ckpt = "flax-community/gpt2-rap-lyric-generator"
tokenizer = AutoTokenizer.from_pretrained(model_ckpt,from_flax=True)
model = AutoModelForCausalLM.from_pretrained(model_ckpt,from_flax=True)
return tokenizer, model
title = st.title("Loading model")
tokenizer, model = load_model()
text_generation = pipeline("text-generation", model=model, tokenizer=tokenizer)
title.title("Rap lyrics generator")
artist = st.text_input("Enter the artist", "Wu-Tang Clan")
song_name = st.text_input("Enter the desired song name", "New York Gangstas")
if st.button("Generate lyrics"):
st.title(f"{artist}: {song_name}")
prefix_text = f"<BOS>{song_name} [Verse 1:{artist}]"
generated_song = text_generation(prefix_text, max_length=750, do_sample=True)[0]
for count, line in enumerate(generated_song['generated_text'].split("\n")):
if count == 0:
st.write(line[line.find('['):])
continue
if"<EOS>" in line:
break
if "<BOS>" in line:
st.write(line[5:])
continue
st.write(line) |