Supiri commited on
Commit
de32ef6
·
1 Parent(s): cb0e849

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+
4
+
5
+ @st.cache
6
+ def load_model():
7
+ model = AutoModelForSeq2SeqLM.from_pretrained(f"Supiri/t5-base-conversation")
8
+ tokenizer = AutoTokenizer.from_pretrained('t5-base')
9
+ return model, tokenizer
10
+
11
+ model, tokenizer = load_model()
12
+
13
+ num_beams = st.slider('Number of beams', min_value=1, max_value=10, value=6)
14
+ num_beam_groups = st.slider('Number of beam groups', min_value=1, max_value=10, value=2)
15
+ diversity_penalty = st.slider('Diversity penalty', min_value=0.1, max_value=5.0, value=2.5)
16
+
17
+ context = st.text_input('Personality', placeholder="Hinata was soft-spoken and polite, always addressing people with proper honourifics. She is kind, always thinking of others more than for herself, caring for their feelings and well-being. She doesn't like being confrontational for any reason. This led to her being meek or timid to others, as her overwhelming kindness can render her unable to respond or act for fear of offending somebody.")
18
+ query = st.text_input('Question', placeHolder="What's your name?")
19
+
20
+ input_ids = tokenizer(f"personality: {context}", f"inquiry: {query}", return_tensors='pt').input_ids
21
+ outputs = model.generate(input_ids, num_beams=num_beams, diversity_penalty=diversity_penalty, num_beam_groups=num_beam_groups)
22
+
23
+ st.write("Bio:\t",context, "\n")
24
+ st.write("Prompt:\t", query)
25
+ st.write("Answer:\t", tokenizer.decode(outputs[0], skip_special_tokens=True), "\n")