File size: 1,151 Bytes
b750931
 
94e7eaf
 
 
b750931
43d6c8d
 
94e7eaf
43d6c8d
b750931
 
94e7eaf
b750931
 
 
 
43d6c8d
b750931
94e7eaf
 
 
b750931
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import streamlit as st

st.set_page_config(page_title = "Q&A Demo")
st.header("Reviewer #2 Bot")
title = st.text_input("Title : ")
submit = st.button("Submit")

model = AutoModelForCausalLM.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0")
model = PeftModel.from_pretrained(model, "shionhonda/tiny-llama-reviewer2-1.1B-dpo-lora")
tokenizer = AutoTokenizer.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0")

prompt = tokenizer.apply_chat_template([
        {"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."},
        {"role": "user", "content": title}
    ], tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt")
generate_ids = model.generate(inputs.input_ids, max_new_tokens=50, do_sample=True, temperature=0.5, top_k=50, top_p=0.95)

if submit:
    st.subheader("Reviewer #2:")
    st.write(tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0])