Truong-Phuc Nguyen
commited on
Commit
•
344f958
1
Parent(s):
0d3ec2f
Update AlphaEdu.py
Browse files- AlphaEdu.py +21 -30
AlphaEdu.py
CHANGED
@@ -1,10 +1,11 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
from plms.language_model import TransformersQG
|
|
|
4 |
import os
|
5 |
import numpy as np
|
6 |
|
7 |
-
st.set_page_config(page_icon='🧪', page_title='ViQAG for Vietnamese Education', layout='
|
8 |
|
9 |
with open(r"./static/styles.css") as f:
|
10 |
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
|
@@ -60,54 +61,44 @@ def generateQA(context, model_path = 'shnl/vit5-vinewsqa-qg-ae'):
|
|
60 |
|
61 |
# =====================================================================================================
|
62 |
|
63 |
-
col_1, col_2, col_3
|
|
|
64 |
|
65 |
-
col_1.markdown("<h8 style='text-align: left; font-weight: normal'>Select your subject:</h8>", unsafe_allow_html=True)
|
66 |
-
subject = col_1.selectbox(label='Select your subject:', options=filenames, label_visibility='collapsed')
|
67 |
-
|
68 |
-
col_2.markdown("<h8 style='text-align: left; font-weight: normal'>Select your grade:</h8>", unsafe_allow_html=True)
|
69 |
list_grades, df = load_grades(file_name=subject)
|
70 |
-
grade = col_2.selectbox(label='
|
71 |
|
72 |
-
col_3.markdown("<h8 style='text-align: left; font-weight: normal'>Select your chapter:</h8>", unsafe_allow_html=True)
|
73 |
list_chapters, df = load_chapters(df=df, grade_name=grade)
|
74 |
-
chapter = col_3.selectbox(label='
|
75 |
|
76 |
-
|
77 |
lesson_names = load_lessons(df=df, grade_name=grade, chapter_name=chapter)
|
78 |
-
lesson =
|
79 |
|
80 |
-
col_5.markdown("<h8 style='text-align: left; font-weight: normal'>Paragraph:</h8>", unsafe_allow_html=True)
|
81 |
total_paragraph, context_values = load_context(df=df, grade_name=grade, chapter_name=chapter, lesson_name=lesson)
|
|
|
|
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
col_11.markdown("<h8 style='text-align: left; font-weight: normal'>Paragraph related:</h8>", unsafe_allow_html=True)
|
87 |
-
paragraph = col_11.text_area(label='Paragraph related', label_visibility='collapsed', height=300, value=context_values[paragraph_idx - 1])
|
88 |
-
|
89 |
-
col_21.markdown("<h8 style='text-align: left; font-weight: normal'>QAG modes:</h8>", unsafe_allow_html=True)
|
90 |
-
col_21.selectbox(label='QAG model:', options=['ViT5-ViNewsQA'], label_visibility='collapsed')
|
91 |
-
|
92 |
-
col_21.markdown("<h8 style='text-align: left; font-weight: normal'>Options:</h8>", unsafe_allow_html=True)
|
93 |
-
btn_show_answer = col_21.toggle(label='Show answers', disabled=False)
|
94 |
|
95 |
-
|
|
|
96 |
|
97 |
if btn_generate == True:
|
98 |
-
with st.spinner(text='Generating QA pairs from the selected
|
99 |
-
st.session_state.output = generateQA(context=
|
100 |
|
101 |
if btn_show_answer:
|
102 |
if st.session_state.output != '':
|
103 |
-
st.markdown("<h8 style='text-align: left; font-weight: normal'>
|
104 |
-
st.code(body=st.session_state.output, language='
|
105 |
else:
|
106 |
pass
|
107 |
else:
|
108 |
if st.session_state.output != '':
|
109 |
-
st.markdown("<h8 style='text-align: left; font-weight: normal'>
|
110 |
output_no_answer = st.session_state.output.split(' [SEP] ')[0].split(', answer: ')[0].replace('question: ', '')
|
111 |
-
st.code(body=output_no_answer, language='
|
112 |
else:
|
113 |
pass
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
from plms.language_model import TransformersQG
|
4 |
+
import time
|
5 |
import os
|
6 |
import numpy as np
|
7 |
|
8 |
+
st.set_page_config(page_icon='🧪', page_title='ViQAG for Vietnamese Education', layout='centered', initial_sidebar_state="collapsed")
|
9 |
|
10 |
with open(r"./static/styles.css") as f:
|
11 |
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
|
|
|
61 |
|
62 |
# =====================================================================================================
|
63 |
|
64 |
+
col_1, col_2, col_3 = st.columns(spec=[2.5, 1.5, 6])
|
65 |
+
subject = col_1.selectbox(label='Subject:', options=filenames, label_visibility='visible')
|
66 |
|
|
|
|
|
|
|
|
|
67 |
list_grades, df = load_grades(file_name=subject)
|
68 |
+
grade = col_2.selectbox(label='Grade:', options=list_grades, label_visibility='visible')
|
69 |
|
|
|
70 |
list_chapters, df = load_chapters(df=df, grade_name=grade)
|
71 |
+
chapter = col_3.selectbox(label='Chapter:', options=list_chapters, label_visibility='visible')
|
72 |
|
73 |
+
col_11, col_21 = st.columns(spec=[8, 2])
|
74 |
lesson_names = load_lessons(df=df, grade_name=grade, chapter_name=chapter)
|
75 |
+
lesson = col_11.selectbox(label='Lesson:', options=lesson_names, label_visibility='visible')
|
76 |
|
|
|
77 |
total_paragraph, context_values = load_context(df=df, grade_name=grade, chapter_name=chapter, lesson_name=lesson)
|
78 |
+
paragraph_idx = col_21.selectbox(label='Paragraph:', options=list(np.arange(1, total_paragraph + 1)), label_visibility='visible')
|
79 |
+
st.text_area(label='Paragraph content', label_visibility='visible', height=200, value=context_values[paragraph_idx - 1])
|
80 |
|
81 |
+
col_13, col_23, col_33, col_43 = st.columns(spec=[0.8, 1.2, 1.2, 0.8])
|
82 |
+
col_23.selectbox(label='QAG model:', options=['ViT5-ViNewsQA'], label_visibility='visible')
|
83 |
+
btn_show_answer = col_33.toggle(label='Show answers', disabled=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
+
col_14, col_24, col_34, col_44, col_54 = st.columns(spec=[1, 1, 1, 1, 1])
|
86 |
+
btn_generate = col_34.button(label='Generate', use_container_width=True)
|
87 |
|
88 |
if btn_generate == True:
|
89 |
+
with st.spinner(text='Generating QA pairs from the selected paragraph. Please wait ...'):
|
90 |
+
st.session_state.output = generateQA(context=context_values)
|
91 |
|
92 |
if btn_show_answer:
|
93 |
if st.session_state.output != '':
|
94 |
+
st.markdown("<h8 style='text-align: left; font-weight: normal'>Generated QA pairs:</h8>", unsafe_allow_html=True)
|
95 |
+
st.code(body=st.session_state.output, language='latex')
|
96 |
else:
|
97 |
pass
|
98 |
else:
|
99 |
if st.session_state.output != '':
|
100 |
+
st.markdown("<h8 style='text-align: left; font-weight: normal'>Generated QA pairs:</h8>", unsafe_allow_html=True)
|
101 |
output_no_answer = st.session_state.output.split(' [SEP] ')[0].split(', answer: ')[0].replace('question: ', '')
|
102 |
+
st.code(body=output_no_answer, language='latex')
|
103 |
else:
|
104 |
pass
|