Spaces:
Runtime error
Runtime error
Morris
commited on
Commit
·
0b82552
1
Parent(s):
725376d
update app.py
Browse files- app.py +35 -9
- notebook.ipynb +0 -0
app.py
CHANGED
@@ -3,12 +3,29 @@ import pandas as pd
|
|
3 |
from PIL import Image
|
4 |
from transformers import pipeline
|
5 |
pipe = pipeline('text-classification', model='tiedaar/short-answer-classification')
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def reset():
|
8 |
st.session_state.ind = False
|
9 |
st.session_state.student_answer = False
|
10 |
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
|
14 |
st.title('iTELL Short Answer Scoring Demo')
|
@@ -30,14 +47,23 @@ if st.session_state.ind:
|
|
30 |
st.text_input("Write your answer here", key='student_answer')
|
31 |
|
32 |
if st.session_state.student_answer:
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
st.button('Reset', on_click=reset)
|
42 |
|
43 |
|
|
|
3 |
from PIL import Image
|
4 |
from transformers import pipeline
|
5 |
pipe = pipeline('text-classification', model='tiedaar/short-answer-classification')
|
6 |
+
bleurt_pipe = pipeline('text-classification', model="vaiibhavgupta/finetuned-bleurt-large")
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("vaiibhavgupta/finetuned-bleurt-large")
|
8 |
+
|
9 |
+
subsections = pd.read_csv('tp-subsections.csv').dropna(axis=0, how='any', subset=['question'])
|
10 |
|
11 |
def reset():
|
12 |
st.session_state.ind = False
|
13 |
st.session_state.student_answer = False
|
14 |
|
15 |
+
def get_mpnet(candidate, reference):
|
16 |
+
text = candidate + '</s>' + reference
|
17 |
+
res = pipe(text)[0]['label']
|
18 |
+
return res
|
19 |
+
|
20 |
+
def get_bleurt(candidate, reference):
|
21 |
+
text = candidate + tokenizer.sep_token + reference
|
22 |
+
score = bleurt_pipe(text)[1]['score']
|
23 |
+
if score > 0.7:
|
24 |
+
return 'correct_answer'
|
25 |
+
else
|
26 |
+
return 'incorrect_answer'
|
27 |
+
|
28 |
+
|
29 |
|
30 |
|
31 |
st.title('iTELL Short Answer Scoring Demo')
|
|
|
47 |
st.text_input("Write your answer here", key='student_answer')
|
48 |
|
49 |
if st.session_state.student_answer:
|
50 |
+
mpnet_res = get_mpnet(st.session_state.student_answer, answer)
|
51 |
+
bleurt_res = get_bleurt(st.session_state.student_answer, answer)
|
52 |
+
col1, col2 = st.columns(2)
|
53 |
+
with col1:
|
54 |
+
if mpnet_res == 'correct_answer':
|
55 |
+
st.image(Image.open('congratulations-meme.jpeg'))
|
56 |
+
st.write('Yay, you got it right!')
|
57 |
+
elif mpnet_res == 'incorrect_answer':
|
58 |
+
st.write('Nope, you said', st.session_state.student_answer)
|
59 |
+
st.write('A better answer would have been', answer)
|
60 |
+
with col2:
|
61 |
+
if bleurt_res == 'correct_answer':
|
62 |
+
st.image(Image.open('congratulations-meme.jpeg'))
|
63 |
+
st.write('Yay, you got it right!')
|
64 |
+
elif bleurt_res == 'incorrect_answer':
|
65 |
+
st.write('Nope, you said', st.session_state.student_answer)
|
66 |
+
st.write('A better answer would have been', answer)
|
67 |
st.button('Reset', on_click=reset)
|
68 |
|
69 |
|
notebook.ipynb
ADDED
File without changes
|