Truong-Phuc Nguyen commited on
Commit
5344f77
1 Parent(s): c300f88

Update AlphaEdu.py

Browse files
Files changed (1) hide show
  1. AlphaEdu.py +16 -14
AlphaEdu.py CHANGED
@@ -2,6 +2,7 @@ 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")
7
 
@@ -13,7 +14,7 @@ st.markdown(f"""
13
  <img src="./app/static/AlphaEdu_logo_trans.png"/>
14
  </div>
15
  """, unsafe_allow_html=True)
16
- st.markdown("<h1 style='text-align: center;'>ViQAG: An Automate Question Answer Generation System for Vietnamese Education</h1>", unsafe_allow_html=True)
17
 
18
  # =====================================================================================================
19
 
@@ -42,7 +43,7 @@ def load_lessons(df, grade_name, chapter_name):
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()
@@ -59,7 +60,7 @@ def generateQA(context, model_path = 'shnl/vit5-vinewsqa-qg-ae'):
59
 
60
  # =====================================================================================================
61
 
62
- col_1, col_2, col_3, col_4 = st.columns(spec=[1, 1, 3, 4])
63
 
64
  col_1.markdown("<h8 style='text-align: left; font-weight: normal'>Select your subject:</h8>", unsafe_allow_html=True)
65
  subject = col_1.selectbox(label='Select your subject:', options=filenames, label_visibility='collapsed')
@@ -76,25 +77,26 @@ col_4.markdown("<h8 style='text-align: left; font-weight: normal'>Select your le
76
  lesson_names = load_lessons(df=df, grade_name=grade, chapter_name=chapter)
77
  lesson = col_4.selectbox(label='Select your lesson:', options=lesson_names, label_visibility='collapsed')
78
 
79
- col_11, col_21 = st.columns(spec=[8, 2])
 
 
 
 
 
80
  col_11.markdown("<h8 style='text-align: left; font-weight: normal'>Paragraph related:</h8>", unsafe_allow_html=True)
81
- context_values = load_context(df=df, grade_name=grade, chapter_name=chapter, lesson_name=lesson)
82
- col_11.text_area(label='Paragraph related', label_visibility='collapsed', height=300, value=context_values)
83
 
84
- col_21.markdown("<h8 style='text-align: left; font-weight: normal'>Choose question generation modes:</h8>", unsafe_allow_html=True)
85
- col_21.checkbox(label='Question Answer Generation', value=True)
86
- col_21.checkbox(label='Multiple Choice Question Generation (Coming soon)', disabled=True)
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
- small_context = context_values.split('\n')[0]
97
- st.session_state.output = generateQA(context=small_context)
98
 
99
  if btn_show_answer:
100
  if st.session_state.output != '':
 
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='wide', initial_sidebar_state="collapsed")
8
 
 
14
  <img src="./app/static/AlphaEdu_logo_trans.png"/>
15
  </div>
16
  """, unsafe_allow_html=True)
17
+ st.markdown("<h1 style='text-align: center;'>AlphaEdu</h1>", unsafe_allow_html=True)
18
 
19
  # =====================================================================================================
20
 
 
43
 
44
  def load_context(df, grade_name, chapter_name, lesson_name):
45
  context = df[(df['grade'] == grade_name) & (df['chapter'] == chapter_name) & (df['lesson'] == lesson_name)]['context'].values
46
+ return len(context), context
47
 
48
  def generateQA(context, model_path = 'shnl/vit5-vinewsqa-qg-ae'):
49
  unique_qa_pairs = set()
 
60
 
61
  # =====================================================================================================
62
 
63
+ col_1, col_2, col_3, col_4, col_5 = st.columns(spec=[1, 1, 3, 3, 1])
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')
 
77
  lesson_names = load_lessons(df=df, grade_name=grade, chapter_name=chapter)
78
  lesson = col_4.selectbox(label='Select your lesson:', options=lesson_names, label_visibility='collapsed')
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
+ paragraph_idx = col_5.selectbox(label='Select your lesson:', options=list(np.arange(1, total_paragraph + 1)), label_visibility='collapsed')
84
+
85
+ col_11, col_21 = st.columns(spec=[9, 1])
86
  col_11.markdown("<h8 style='text-align: left; font-weight: normal'>Paragraph related:</h8>", unsafe_allow_html=True)
87
+ 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
  btn_generate = col_21.button(label='Generate questions', use_container_width=True)
96
 
97
  if btn_generate == True:
98
+ with st.spinner(text='Generating QA pairs from the selected context. Please wait ...'):
99
+ st.session_state.output = generateQA(context=context_values)
 
100
 
101
  if btn_show_answer:
102
  if st.session_state.output != '':