Morris commited on
Commit
0b82552
·
1 Parent(s): 725376d

update app.py

Browse files
Files changed (2) hide show
  1. app.py +35 -9
  2. 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
- subsections = pd.read_csv('tp-subsections.csv').dropna(axis=0, how='any', subset=['question'])
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- text = st.session_state.student_answer + '</s>' + answer
34
- res = pipe(text)[0]['label']
35
- if res == 'correct_answer':
36
- st.image(Image.open('congratulations-meme.jpeg'))
37
- st.write('Yay, you got it right!')
38
- elif res == 'incorrect_answer':
39
- st.write('Nope, you said', st.session_state.student_answer)
40
- st.write('A better answer would have been', answer)
 
 
 
 
 
 
 
 
 
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