Spaces:
Build error
Build error
Commit
·
6bf8905
1
Parent(s):
c10d737
initial commit
Browse files- app.py +57 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import torch
|
3 |
+
from transformers import BartForConditionalGeneration, BartTokenizer
|
4 |
+
|
5 |
+
# initialize model + tok variables
|
6 |
+
model = None
|
7 |
+
tok = None
|
8 |
+
|
9 |
+
# Examples for each models
|
10 |
+
examples = [
|
11 |
+
["interview-question-remake", "I have a cat named dolche and he's not very friendly with strangers. I've had him for 9 years now and it has been a pleasure to see him grow closer to us every year."],
|
12 |
+
["interview-length-tagged","Today's weather was really nice."],
|
13 |
+
["reverse-interview-question", "There are so many incredible musicians out there and so many really compelling big hits this year that it makes for a really interesting way to recap some of those big events."]
|
14 |
+
]
|
15 |
+
|
16 |
+
# Descriptions for each models
|
17 |
+
# descriptions = "Interview question remake is a model that..."
|
18 |
+
|
19 |
+
# pass in Strings of model choice and input text for context
|
20 |
+
def genQuestion(model_choice, context):
|
21 |
+
# global descriptions
|
22 |
+
if model_choice=="interview-question-remake":
|
23 |
+
model = BartForConditionalGeneration.from_pretrained("hyechanjun/interview-question-remake")
|
24 |
+
tok = BartTokenizer.from_pretrained("hyechanjun/interview-question-remake")
|
25 |
+
# descriptions = "Interview question remake is a model that..."
|
26 |
+
elif model_choice=="interview-length-tagged":
|
27 |
+
model = BartForConditionalGeneration.from_pretrained("hyechanjun/interview-length-tagged")
|
28 |
+
tok = BartTokenizer.from_pretrained("hyechanjun/interview-length-tagged")
|
29 |
+
# descriptions = "Interview question tagged is a model that..."
|
30 |
+
elif model_choice=="reverse-interview-question":
|
31 |
+
model = BartForConditionalGeneration.from_pretrained("hyechanjun/reverse-interview-question")
|
32 |
+
tok = BartTokenizer.from_pretrained("hyechanjun/reverse-interview-question")
|
33 |
+
# descriptions = "Reverse interview question is a model that..."
|
34 |
+
|
35 |
+
inputs = tok(context, return_tensors="pt")
|
36 |
+
output = model.generate(inputs["input_ids"], num_beams=4, max_length=64, min_length=9, num_return_sequences=4, diversity_penalty =1.0, num_beam_groups=4)
|
37 |
+
final_output = ''
|
38 |
+
|
39 |
+
for i in range(4):
|
40 |
+
final_output += [tok.decode(beam, skip_special_tokens=True, clean_up_tokenization_spaces=False) for beam in output][i] + "\n"
|
41 |
+
|
42 |
+
return final_output
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
# Title
|
47 |
+
st.title("Interview AI Test Website")
|
48 |
+
|
49 |
+
# Input field
|
50 |
+
input = st.text_input('Context')
|
51 |
+
|
52 |
+
option = st.selectbox(
|
53 |
+
'Please select a model.',
|
54 |
+
('interview-question-remake', 'interview-length-tagged', 'reverse-interview-question'))
|
55 |
+
|
56 |
+
if st.button('Submit'):
|
57 |
+
genQuestion(option, input)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|