Truong-Phuc Nguyen
commited on
Update AlphaEdu.py
Browse files- AlphaEdu.py +85 -54
AlphaEdu.py
CHANGED
|
@@ -1,55 +1,86 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
st.markdown(f""
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import time
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
st.set_page_config(page_icon='🧪', page_title='ViQAG for Vietnamese Education', layout='wide', initial_sidebar_state="collapsed")
|
| 7 |
+
|
| 8 |
+
with open(r"./static/styles.css") as f:
|
| 9 |
+
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
|
| 10 |
+
|
| 11 |
+
st.markdown(f"""
|
| 12 |
+
<div class=logo_area>
|
| 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 |
+
|
| 20 |
+
def file_selector(folder_path=r'./Resources/'):
|
| 21 |
+
filenames = os.listdir(folder_path)
|
| 22 |
+
return filenames
|
| 23 |
+
filenames = file_selector()
|
| 24 |
+
|
| 25 |
+
def load_grades(file_name, folder_path=r'./Resources/'):
|
| 26 |
+
file_path = f"{folder_path}{file_name}"
|
| 27 |
+
df = pd.read_csv(file_path)
|
| 28 |
+
list_grades = df['grade'].drop_duplicates().values
|
| 29 |
+
return list_grades, df
|
| 30 |
+
|
| 31 |
+
def load_chapters(df, grade_name):
|
| 32 |
+
df_raw = df[df['grade'] == grade_name]
|
| 33 |
+
list_chapters = df_raw['chapter'].drop_duplicates().values
|
| 34 |
+
return list_chapters, df
|
| 35 |
+
|
| 36 |
+
def load_lessons(df, grade_name, chapter_name):
|
| 37 |
+
df_raw = df[(df['grade'] == grade_name) & (df['chapter'] == chapter_name)]
|
| 38 |
+
return df_raw['lesson'].drop_duplicates().values
|
| 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])
|
| 47 |
+
|
| 48 |
+
col_1.markdown("<h8 style='text-align: left; font-weight: normal'>Select your subject:</h8>", unsafe_allow_html=True)
|
| 49 |
+
subject = col_1.selectbox(label='Select your subject:', options=filenames, label_visibility='collapsed')
|
| 50 |
+
|
| 51 |
+
col_2.markdown("<h8 style='text-align: left; font-weight: normal'>Select your grade:</h8>", unsafe_allow_html=True)
|
| 52 |
+
list_grades, df = load_grades(file_name=subject)
|
| 53 |
+
grade = col_2.selectbox(label='Select your grade:', options=list_grades, label_visibility='collapsed')
|
| 54 |
+
|
| 55 |
+
col_3.markdown("<h8 style='text-align: left; font-weight: normal'>Select your chapter:</h8>", unsafe_allow_html=True)
|
| 56 |
+
list_chapters, df = load_chapters(df=df, grade_name=grade)
|
| 57 |
+
chapter = col_3.selectbox(label='Select your chapter:', options=list_chapters, label_visibility='collapsed')
|
| 58 |
+
|
| 59 |
+
col_4.markdown("<h8 style='text-align: left; font-weight: normal'>Select your lesson:</h8>", unsafe_allow_html=True)
|
| 60 |
+
lesson_names = load_lessons(df=df, grade_name=grade, chapter_name=chapter)
|
| 61 |
+
lesson = col_4.selectbox(label='Select your lesson:', options=lesson_names, label_visibility='collapsed')
|
| 62 |
+
|
| 63 |
+
col_11, col_21 = st.columns(spec=[8, 2])
|
| 64 |
+
col_11.markdown("<h8 style='text-align: left; font-weight: normal'>Paragraph related:</h8>", unsafe_allow_html=True)
|
| 65 |
+
context_values = load_context(df=df, grade_name=grade, chapter_name=chapter, lesson_name=lesson)
|
| 66 |
+
col_11.text_area(label='Paragraph related', label_visibility='collapsed', height=300, value=context_values)
|
| 67 |
+
|
| 68 |
+
col_21.markdown("<h8 style='text-align: left; font-weight: normal'>Choose question generation modes:</h8>", unsafe_allow_html=True)
|
| 69 |
+
col_21.checkbox(label='Question Answer Generation', value=True)
|
| 70 |
+
col_21.checkbox(label='Multiple Choice Question Generation (Coming soon)', disabled=True)
|
| 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=True)
|
| 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 |
+
time.sleep(5)
|
| 81 |
+
|
| 82 |
+
st.markdown("<h8 style='text-align: left; font-weight: normal'>Your questions and answers has been generated:</h8>", unsafe_allow_html=True)
|
| 83 |
+
output = '''question: <question_1>, answer: <Có cái njt :v Chưa cập nhật xong :v> [SEP] \nquestion: <question_2>, answer: <answer_2> [SEP] \nquestion: <question_3>, answer: <answer_3> [SEP] \nquestion: <question_4>, answer: <answer_4> [SEP] \nquestion: <question_5>, answer: <answer_5> [SEP]\nquestion: <question_6>, answer: <answer_6> [SEP]\nquestion: <question_7>, answer: <answer_7> [SEP]\nquestion: <question_8>, answer: <answer_8> [SEP]\nquestion: <question_9>, answer: <answer_9> [SEP]\nquestion: <question_10>, answer: <answer_10> [SEP]'''
|
| 84 |
+
st.code(body=output, language='wiki')
|
| 85 |
+
|
| 86 |
|