Spaces:
Sleeping
Sleeping
File size: 1,305 Bytes
63f3383 b168e68 24f2e60 b168e68 0a2a6c5 63f3383 b168e68 24f2e60 b168e68 63f3383 b168e68 07aebcc 63f3383 b168e68 83c7cf8 b168e68 f829e6e 51a8c67 2195eff 07aebcc 2195eff 1c8c3b4 b168e68 |
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 transformers import AutoTokenizer, AutoModelForCausalLM
import torch
# Load the Phi 2 model and tokenizer
tokenizer = AutoTokenizer.from_pretrained(
"microsoft/phi-2",
trust_remote_code=True
)
tokenizer.pad_token=tokenizer.eos_token
model = AutoModelForCausalLM.from_pretrained(
"arieridwans/phi_2-finetuned-lyrics",
device_map="auto",
trust_remote_code=True
)
# Streamlit UI
st.title("Eleanor Rigby")
# User input prompt
user_prompt = st.text_area("Enter your prompt that can be song lyrics:", """Yesterday, I saw you in my dream""")
# Generate output based on user input
if st.button("Generate Output"):
instruct_prompt = "Instruct:You are a song writer and your main reference is The Beatles. Write a song lyrics by completing these words:"
output_prompt = "Output:"
input = tokenizer(""" {0}{1}\n{2} """.format(instruct_prompt, user_prompt, output_prompt),
return_tensors="pt",
return_attention_mask=False,
padding=True,
truncation=True)
result = inference_model.generate(**input, repetition_penalty=1.2, max_length=1024)
output = tokenizer.batch_decode(result, skip_special_tokens=True)[0]
st.text("Generated Result:")
st.write(output) |