Truong-Phuc Nguyen
commited on
Commit
•
2704216
1
Parent(s):
1c3fa80
Update AlphaEdu.py
Browse files- AlphaEdu.py +37 -13
AlphaEdu.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
-
import
|
4 |
import os
|
5 |
|
6 |
st.set_page_config(page_icon='🧪', page_title='ViQAG for Vietnamese Education', layout='wide', initial_sidebar_state="collapsed")
|
@@ -17,6 +17,9 @@ st.markdown("<h1 style='text-align: center;'>ViQAG: An Automate Question Answer
|
|
17 |
|
18 |
# =====================================================================================================
|
19 |
|
|
|
|
|
|
|
20 |
def file_selector(folder_path=r'./Resources/'):
|
21 |
filenames = os.listdir(folder_path)
|
22 |
return filenames
|
@@ -39,8 +42,21 @@ def load_lessons(df, grade_name, chapter_name):
|
|
39 |
|
40 |
def load_context(df, grade_name, chapter_name, lesson_name):
|
41 |
context = df[(df['grade'] == grade_name) & (df['chapter'] == chapter_name) & (df['lesson'] == lesson_name)]['context'].values
|
42 |
-
return '\n'.join(context.tolist())
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
# =====================================================================================================
|
45 |
|
46 |
col_1, col_2, col_3, col_4 = st.columns(spec=[1, 1, 3, 4])
|
@@ -71,16 +87,24 @@ col_21.checkbox(label='Multiple Choice Question Generation (Coming soon)', disab
|
|
71 |
col_21.checkbox(label='Fill-in-the-Blank Question Generation (Coming soon)', disabled=True)
|
72 |
|
73 |
col_21.markdown("<h8 style='text-align: left; font-weight: normal'>Options:</h8>", unsafe_allow_html=True)
|
74 |
-
btn_show_answer = col_21.toggle(label='Show the answers', disabled=
|
75 |
|
76 |
btn_generate = col_21.button(label='Generate questions', use_container_width=True)
|
77 |
|
78 |
-
if btn_generate:
|
79 |
-
with st.spinner(text='Generating...'):
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
output
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
+
from plms.language_model import TransformersQG
|
4 |
import os
|
5 |
|
6 |
st.set_page_config(page_icon='🧪', page_title='ViQAG for Vietnamese Education', layout='wide', initial_sidebar_state="collapsed")
|
|
|
17 |
|
18 |
# =====================================================================================================
|
19 |
|
20 |
+
if 'output' not in st.session_state:
|
21 |
+
st.session_state.output = ''
|
22 |
+
|
23 |
def file_selector(folder_path=r'./Resources/'):
|
24 |
filenames = os.listdir(folder_path)
|
25 |
return filenames
|
|
|
42 |
|
43 |
def load_context(df, grade_name, chapter_name, lesson_name):
|
44 |
context = df[(df['grade'] == grade_name) & (df['chapter'] == chapter_name) & (df['lesson'] == lesson_name)]['context'].values
|
45 |
+
return '\n'.join([str(item) for item in context.tolist()])
|
46 |
+
|
47 |
+
def generateQA(context, model_path = 'shnl/vit5-vinewsqa-qg-ae'):
|
48 |
+
unique_qa_pairs = set()
|
49 |
+
model = TransformersQG(model=model_path, max_length=512)
|
50 |
+
output = model.generate_qa(context)
|
51 |
+
qa_pairs = ''
|
52 |
+
for item in output:
|
53 |
+
question, answer = item
|
54 |
+
if (question, answer) not in unique_qa_pairs:
|
55 |
+
qa_pairs += f'question: {question} \nanswer: {answer} [SEP] '
|
56 |
+
unique_qa_pairs.add((question, answer))
|
57 |
+
qa = '\n\n'.join(qa_pairs.split(' [SEP] '))
|
58 |
+
return qa
|
59 |
+
|
60 |
# =====================================================================================================
|
61 |
|
62 |
col_1, col_2, col_3, col_4 = st.columns(spec=[1, 1, 3, 4])
|
|
|
87 |
col_21.checkbox(label='Fill-in-the-Blank Question Generation (Coming soon)', disabled=True)
|
88 |
|
89 |
col_21.markdown("<h8 style='text-align: left; font-weight: normal'>Options:</h8>", unsafe_allow_html=True)
|
90 |
+
btn_show_answer = col_21.toggle(label='Show the answers', disabled=False)
|
91 |
|
92 |
btn_generate = col_21.button(label='Generate questions', use_container_width=True)
|
93 |
|
94 |
+
if btn_generate == True:
|
95 |
+
with st.spinner(text='Generating 10 pairs questions-answers. Please wait ...'):
|
96 |
+
st.session_state.output = generateQA(context=context_values)
|
97 |
+
|
98 |
+
if btn_show_answer:
|
99 |
+
if st.session_state.output != '':
|
100 |
+
st.markdown("<h8 style='text-align: left; font-weight: normal'>Your questions and answers has been generated:</h8>", unsafe_allow_html=True)
|
101 |
+
st.code(body=st.session_state.output, language='wiki')
|
102 |
+
else:
|
103 |
+
pass
|
104 |
+
else:
|
105 |
+
if st.session_state.output != '':
|
106 |
+
st.markdown("<h8 style='text-align: left; font-weight: normal'>Your questions and answers has been generated:</h8>", unsafe_allow_html=True)
|
107 |
+
output_no_answer = st.session_state.output.split(' [SEP] ')[0].split(', answer: ')[0].replace('question: ', '')
|
108 |
+
st.code(body=output_no_answer, language='wiki')
|
109 |
+
else:
|
110 |
+
pass
|