Morris
commited on
Commit
·
db80f93
1
Parent(s):
5fcb9d9
update app.py
Browse files
app.py
CHANGED
@@ -11,87 +11,78 @@ key: str = os.environ.get("SUPABASE_KEY")
|
|
11 |
supabase: Client = create_client(url, key)
|
12 |
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
# st.write('A better answer would have been: ', answer)
|
87 |
-
# st.button('Reset', on_click=reset)
|
88 |
-
# entry = {"subsection":st.session_state.ind, "source":passage, "question":question, "answer":answer, "mpnet_response":mpnet_res, "bleurt_response":bleurt_res, "correct_response":is_correct}
|
89 |
-
# output.loc[len(output)] = (entry)
|
90 |
-
# output_ds = Dataset.from_pandas(output)
|
91 |
-
# output_ds.push_to_hub(DATASET_REPO)
|
92 |
-
|
93 |
-
# else:
|
94 |
-
# st.write("Please indicate whether you are providing a correct answer.")
|
95 |
|
96 |
|
97 |
|
|
|
11 |
supabase: Client = create_client(url, key)
|
12 |
|
13 |
|
14 |
+
pipe = pipeline('text-classification', model='tiedaar/short-answer-classification')
|
15 |
+
bleurt_pipe = pipeline('text-classification', model="vaiibhavgupta/finetuned-bleurt-large")
|
16 |
+
tokenizer = AutoTokenizer.from_pretrained("vaiibhavgupta/finetuned-bleurt-large")
|
17 |
+
|
18 |
+
subsections = pd.read_csv('tp-subsections.csv').dropna(axis=0, how='any', subset=['question'])
|
19 |
+
|
20 |
+
def reset():
|
21 |
+
st.session_state.ind = False
|
22 |
+
st.session_state.student_answer = False
|
23 |
+
|
24 |
+
def get_mpnet(candidate, reference):
|
25 |
+
text = candidate + '</s>' + reference
|
26 |
+
res = pipe(text)[0]['label']
|
27 |
+
return res
|
28 |
+
|
29 |
+
def get_bleurt(candidate, reference):
|
30 |
+
text = candidate + tokenizer.sep_token + reference
|
31 |
+
score = bleurt_pipe(text)[0]['score']
|
32 |
+
if score > 0.7:
|
33 |
+
return 'correct_answer'
|
34 |
+
else:
|
35 |
+
return 'incorrect_answer'
|
36 |
+
|
37 |
+
st.title('iTELL Short Answer Scoring Demo')
|
38 |
+
st.image(Image.open('learlabaialoe.JPG'))
|
39 |
+
st.subheader('This is a demonstration of the iTELL short answer scoring model. You will be provided with a passage from the textbook Think Python and a question. Please provide a short answer to the question.')
|
40 |
+
st.slider('Use this slider to choose your subsection.', min_value=0, max_value=len(subsections), key='ind')
|
41 |
+
|
42 |
+
if st.session_state.ind:
|
43 |
+
student_answer = False
|
44 |
+
passage = subsections.iloc[st.session_state.ind]['clean_text']
|
45 |
+
question = subsections.iloc[st.session_state.ind]['question']
|
46 |
+
answer = subsections.iloc[st.session_state.ind]['answer']
|
47 |
+
st.markdown('---')
|
48 |
+
st.header('Passage')
|
49 |
+
st.write(passage)
|
50 |
+
st.markdown('---')
|
51 |
+
st.header('Question')
|
52 |
+
st.write(question)
|
53 |
+
is_correct = st.radio("Are you writing a correct answer?", ["Yes", "No"])
|
54 |
+
st.text_input("Write your answer here", key='student_answer')
|
55 |
+
|
56 |
+
if st.session_state.student_answer:
|
57 |
+
if is_correct:
|
58 |
+
mpnet_res = get_mpnet(st.session_state.student_answer, answer)
|
59 |
+
bleurt_res = get_bleurt(st.session_state.student_answer, answer)
|
60 |
+
col1, col2 = st.columns(2)
|
61 |
+
with col1:
|
62 |
+
if mpnet_res == 'correct_answer':
|
63 |
+
st.subheader('MPnet says yes!')
|
64 |
+
st.image(Image.open('congratulations-meme.jpeg'))
|
65 |
+
st.write('Yay, you got it right!')
|
66 |
+
elif mpnet_res == 'incorrect_answer':
|
67 |
+
st.subheader('MPnet says no!')
|
68 |
+
st.write('Nope, you said', st.session_state.student_answer)
|
69 |
+
st.write('A better answer would have been: ', answer)
|
70 |
+
with col2:
|
71 |
+
if bleurt_res == 'correct_answer':
|
72 |
+
st.subheader('Bleurt says yes!')
|
73 |
+
st.image(Image.open('congratulations-meme.jpeg'))
|
74 |
+
st.write('Yay, you got it right!')
|
75 |
+
elif bleurt_res == 'incorrect_answer':
|
76 |
+
st.subheader('Bleurt says no!')
|
77 |
+
st.write('Nope, you said', st.session_state.student_answer)
|
78 |
+
st.write('A better answer would have been: ', answer)
|
79 |
+
st.button('Reset', on_click=reset)
|
80 |
+
entry = {"subsection":st.session_state.ind, "source":passage, "question":question, "answer":answer, "mpnet_response":mpnet_res, "bleurt_response":bleurt_res, "correct_response":is_correct}
|
81 |
+
data, count = supabase.table('automatic-short-answer-scoring') \
|
82 |
+
.insert(entry).execute()
|
83 |
+
|
84 |
+
else:
|
85 |
+
st.write("Please indicate whether you are providing a correct answer.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
|
88 |
|