Morris commited on
Commit
db80f93
·
1 Parent(s): 5fcb9d9

update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -81
app.py CHANGED
@@ -11,87 +11,78 @@ key: str = os.environ.get("SUPABASE_KEY")
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
- text = st.text_input("Write your answer here")
21
- if text:
22
- data, count = supabase.table('automatic-short-answer-scoring') \
23
- .insert({"subsection": 1, "question": "Denmark", "answer":text}).execute()
24
-
25
-
26
-
27
-
28
- # def reset():
29
- # st.session_state.ind = False
30
- # st.session_state.student_answer = False
31
-
32
- # def get_mpnet(candidate, reference):
33
- # text = candidate + '</s>' + reference
34
- # res = pipe(text)[0]['label']
35
- # return res
36
-
37
- # def get_bleurt(candidate, reference):
38
- # text = candidate + tokenizer.sep_token + reference
39
- # score = bleurt_pipe(text)[0]['score']
40
- # if score > 0.7:
41
- # return 'correct_answer'
42
- # else:
43
- # return 'incorrect_answer'
44
-
45
- # st.title('iTELL Short Answer Scoring Demo')
46
- # st.image(Image.open('learlabaialoe.JPG'))
47
- # 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.')
48
- # st.slider('Use this slider to choose your subsection.', min_value=0, max_value=len(subsections), key='ind')
49
-
50
- # if st.session_state.ind:
51
- # student_answer = False
52
- # passage = subsections.iloc[st.session_state.ind]['clean_text']
53
- # question = subsections.iloc[st.session_state.ind]['question']
54
- # answer = subsections.iloc[st.session_state.ind]['answer']
55
- # st.markdown('---')
56
- # st.header('Passage')
57
- # st.write(passage)
58
- # st.markdown('---')
59
- # st.header('Question')
60
- # st.write(question)
61
- # is_correct = st.radio("Are you writing a correct answer?", ["Yes", "No"])
62
- # st.text_input("Write your answer here", key='student_answer')
63
-
64
- # if st.session_state.student_answer:
65
- # if is_correct:
66
- # mpnet_res = get_mpnet(st.session_state.student_answer, answer)
67
- # bleurt_res = get_bleurt(st.session_state.student_answer, answer)
68
- # col1, col2 = st.columns(2)
69
- # with col1:
70
- # if mpnet_res == 'correct_answer':
71
- # st.subheader('MPnet says yes!')
72
- # st.image(Image.open('congratulations-meme.jpeg'))
73
- # st.write('Yay, you got it right!')
74
- # elif mpnet_res == 'incorrect_answer':
75
- # st.subheader('MPnet says no!')
76
- # st.write('Nope, you said', st.session_state.student_answer)
77
- # st.write('A better answer would have been: ', answer)
78
- # with col2:
79
- # if bleurt_res == 'correct_answer':
80
- # st.subheader('Bleurt says yes!')
81
- # st.image(Image.open('congratulations-meme.jpeg'))
82
- # st.write('Yay, you got it right!')
83
- # elif bleurt_res == 'incorrect_answer':
84
- # st.subheader('Bleurt says no!')
85
- # st.write('Nope, you said', st.session_state.student_answer)
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