Spaces:
Sleeping
Sleeping
arieridwans
commited on
Commit
•
63f3383
1
Parent(s):
0dab728
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import subprocess
|
3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
4 |
+
import torch
|
5 |
+
|
6 |
+
st.title('Eleanor Rigby')
|
7 |
+
|
8 |
+
inference_model = AutoModelForCausalLM.from_pretrained("microsoft/phi_2-finetuned-lyrics", trust_remote_code=True, torch_dtype=torch.float32)
|
9 |
+
inference_tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-2", use_fast=True)
|
10 |
+
inference_tokenizer.pad_token=inference_tokenizer.eos_token
|
11 |
+
|
12 |
+
user_prompt = st.text_area("Enter your prompt that can be song lyrics", "E.g. Yesterday, I saw you in my dream")
|
13 |
+
|
14 |
+
if st.button("Generate Output"):
|
15 |
+
instruct_prompt = "Instruct:You are a song writer and your main reference is The Beatles. Write a song lyrics by completing these words:"
|
16 |
+
output_prompt = " Output:"
|
17 |
+
input = inference_tokenizer(""" {0}{1}\n{2} """.format(instruct_prompt, user_prompt, output_prompt),
|
18 |
+
return_tensors="pt",
|
19 |
+
return_attention_mask=False,
|
20 |
+
padding=True,
|
21 |
+
truncation=True)
|
22 |
+
result = inference_model.generate(**input, repetition_penalty=1.2, max_length=1024)
|
23 |
+
output = inference_tokenizer.batch_decode(result, skip_special_tokens=True)[0]
|
24 |
+
st.text("Generated Output:")
|
25 |
+
st.write(output)
|