arieridwans commited on
Commit
f829e6e
1 Parent(s): 7cca8dc

Update button click event

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -9,17 +9,19 @@ inference_model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", trust_
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)
 
 
 
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
+ def run_inference():
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)
26
+
27
+ st.button('Generate Output', on_click=run_inference)