shionhonda commited on
Commit
43d6c8d
1 Parent(s): b750931

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -6
app.py CHANGED
@@ -1,25 +1,23 @@
1
  from transformers import AutoTokenizer, AutoModelForCausalLM
2
  from peft import PeftModel
3
- import accelerate
4
  import streamlit as st
5
 
6
  st.set_page_config(page_title = "Q&A Demo")
7
  st.header("Reviewer #2 Bot")
 
 
8
 
9
- model = AutoModelForCausalLM.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0").cuda()
10
  model = PeftModel.from_pretrained(model, "shionhonda/tiny-llama-reviewer2-1.1B-dpo-lora")
11
  tokenizer = AutoTokenizer.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0")
12
 
13
- title = st.text_input("Title : ")
14
  prompt = tokenizer.apply_chat_template([
15
  {"role": "system", "content": "You are an experienced researcher and a reviewer of scientific papers. Given a title of the paper, write a review about it in one sentence."},
16
  {"role": "user", "content": title}
17
  ], tokenize=False, add_generation_prompt=True)
18
- inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
19
  generate_ids = model.generate(inputs.input_ids, max_new_tokens=50, do_sample=True, temperature=0.5, top_k=50, top_p=0.95)
20
 
21
- submit = st.button("Submit")
22
-
23
  if submit:
24
  st.subheader("Reviewer #2:")
25
  st.write(tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0])
 
1
  from transformers import AutoTokenizer, AutoModelForCausalLM
2
  from peft import PeftModel
 
3
  import streamlit as st
4
 
5
  st.set_page_config(page_title = "Q&A Demo")
6
  st.header("Reviewer #2 Bot")
7
+ title = st.text_input("Title : ")
8
+ submit = st.button("Submit")
9
 
10
+ model = AutoModelForCausalLM.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0")
11
  model = PeftModel.from_pretrained(model, "shionhonda/tiny-llama-reviewer2-1.1B-dpo-lora")
12
  tokenizer = AutoTokenizer.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0")
13
 
 
14
  prompt = tokenizer.apply_chat_template([
15
  {"role": "system", "content": "You are an experienced researcher and a reviewer of scientific papers. Given a title of the paper, write a review about it in one sentence."},
16
  {"role": "user", "content": title}
17
  ], tokenize=False, add_generation_prompt=True)
18
+ inputs = tokenizer(prompt, return_tensors="pt")
19
  generate_ids = model.generate(inputs.input_ids, max_new_tokens=50, do_sample=True, temperature=0.5, top_k=50, top_p=0.95)
20
 
 
 
21
  if submit:
22
  st.subheader("Reviewer #2:")
23
  st.write(tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0])