Spaces:
Sleeping
Sleeping
Upload MisconceptTutor.py
Browse files- MisconceptTutor.py +404 -0
MisconceptTutor.py
ADDED
@@ -0,0 +1,404 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import os
|
4 |
+
from src.SecondModule.module2 import SimilarQuestionGenerator
|
5 |
+
import logging
|
6 |
+
from typing import Optional, Tuple
|
7 |
+
logging.basicConfig(level=logging.DEBUG)
|
8 |
+
|
9 |
+
|
10 |
+
# Streamlit ํ์ด์ง ๊ธฐ๋ณธ ์ค์
|
11 |
+
st.set_page_config(
|
12 |
+
page_title="MisconcepTutor",
|
13 |
+
layout="wide",
|
14 |
+
initial_sidebar_state="expanded"
|
15 |
+
)
|
16 |
+
|
17 |
+
# ๊ฒฝ๋ก ์ค์
|
18 |
+
base_path = os.path.dirname(os.path.abspath(__file__))
|
19 |
+
data_path = os.path.join(base_path, 'Data')
|
20 |
+
misconception_csv_path = os.path.join(data_path, 'misconception_mapping.csv')
|
21 |
+
|
22 |
+
# ๋ก๊น
์ค์
|
23 |
+
logging.basicConfig(level=logging.INFO)
|
24 |
+
logger = logging.getLogger(__name__)
|
25 |
+
|
26 |
+
# ์ธ์
์ํ ์ด๊ธฐํ - ๊ฐ์ฅ ๋จผ์ ์คํ๋๋๋ก ์ต์๋จ์ ๋ฐฐ์น
|
27 |
+
if 'initialized' not in st.session_state:
|
28 |
+
st.session_state.initialized = True
|
29 |
+
st.session_state.wrong_questions = []
|
30 |
+
st.session_state.misconceptions = []
|
31 |
+
st.session_state.current_question_index = 0
|
32 |
+
st.session_state.generated_questions = []
|
33 |
+
st.session_state.current_step = 'initial'
|
34 |
+
st.session_state.selected_wrong_answer = None
|
35 |
+
st.session_state.questions = []
|
36 |
+
logger.info("Session state initialized")
|
37 |
+
|
38 |
+
# ๋ฌธ์ ์์ฑ๊ธฐ ์ด๊ธฐํ
|
39 |
+
@st.cache_resource
|
40 |
+
def load_question_generator():
|
41 |
+
"""๋ฌธ์ ์์ฑ ๋ชจ๋ธ ๋ก๋"""
|
42 |
+
if not os.path.exists(misconception_csv_path):
|
43 |
+
st.error(f"CSV ํ์ผ์ด ์กด์ฌํ์ง ์์ต๋๋ค: {misconception_csv_path}")
|
44 |
+
raise FileNotFoundError(f"CSV ํ์ผ์ด ์กด์ฌํ์ง ์์ต๋๋ค: {misconception_csv_path}")
|
45 |
+
return SimilarQuestionGenerator(misconception_csv_path=misconception_csv_path)
|
46 |
+
|
47 |
+
# CSV ๋ฐ์ดํฐ ๋ก๋ ํจ์
|
48 |
+
@st.cache_data
|
49 |
+
def load_data(data_file = '/train.csv'):
|
50 |
+
try:
|
51 |
+
file_path = os.path.join(data_path, data_file.lstrip('/'))
|
52 |
+
df = pd.read_csv(file_path)
|
53 |
+
logger.info(f"Data loaded successfully from {file_path}")
|
54 |
+
return df
|
55 |
+
except FileNotFoundError:
|
56 |
+
st.error(f"ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค: {data_file}")
|
57 |
+
logger.error(f"File not found: {data_file}")
|
58 |
+
return None
|
59 |
+
|
60 |
+
def start_quiz():
|
61 |
+
"""ํด์ฆ ์์ ๋ฐ ์ด๊ธฐํ"""
|
62 |
+
df = load_data()
|
63 |
+
if df is None or df.empty:
|
64 |
+
st.error("๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์ฌ ์ ์์ต๋๋ค. ๋ฐ์ดํฐ์
์ ํ์ธํด์ฃผ์ธ์.")
|
65 |
+
return
|
66 |
+
|
67 |
+
st.session_state.questions = df.sample(n=10, random_state=42)
|
68 |
+
st.session_state.current_step = 'quiz'
|
69 |
+
st.session_state.current_question_index = 0
|
70 |
+
st.session_state.wrong_questions = []
|
71 |
+
st.session_state.misconceptions = []
|
72 |
+
st.session_state.generated_questions = []
|
73 |
+
logger.info("Quiz started")
|
74 |
+
|
75 |
+
# def generate_similar_question(wrong_q, misconception_id, generator):
|
76 |
+
# """์ ์ฌ ๋ฌธ์ ์์ฑ"""
|
77 |
+
# if not isinstance(wrong_q, dict):
|
78 |
+
# logger.error(f"Invalid wrong_q type: {type(wrong_q)}")
|
79 |
+
# st.error("์ ์ฌ ๋ฌธ์ ์์ฑ์ ํ์ํ ๋ฐ์ดํฐ ํ์์ด ์๋ชป๋์์ต๋๋ค.")
|
80 |
+
# return None
|
81 |
+
|
82 |
+
# try:
|
83 |
+
# generated_q, _ = generator.generate_similar_question_with_text(
|
84 |
+
# construct_name=wrong_q['ConstructName'],
|
85 |
+
# subject_name=wrong_q['SubjectName'],
|
86 |
+
# question_text=wrong_q['QuestionText'],
|
87 |
+
# correct_answer_text=wrong_q[f'Answer{wrong_q["CorrectAnswer"]}Text'],
|
88 |
+
# wrong_answer_text=wrong_q[f'Answer{st.session_state.selected_wrong_answer}Text'],
|
89 |
+
# misconception_id=misconception_id
|
90 |
+
# )
|
91 |
+
|
92 |
+
# if generated_q:
|
93 |
+
# return {
|
94 |
+
# 'question': generated_q.question,
|
95 |
+
# 'choices': generated_q.choices,
|
96 |
+
# 'correct': generated_q.correct_answer,
|
97 |
+
# 'explanation': generated_q.explanation
|
98 |
+
# }
|
99 |
+
# except Exception as e:
|
100 |
+
# logger.error(f"Error generating similar question: {e}")
|
101 |
+
# st.error(f"๋ฌธ์ ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.")
|
102 |
+
# return None
|
103 |
+
|
104 |
+
# def generate_similar_question(wrong_q, misconception_id, generator):
|
105 |
+
# """์ ์ฌ ๋ฌธ์ ์์ฑ"""
|
106 |
+
# # ์
๋ ฅ ๋ฐ์ดํฐ ํ์ธ
|
107 |
+
# logger.info(f"Generating similar question for misconception_id: {misconception_id}")
|
108 |
+
# logger.info(f"Wrong question data type: {type(wrong_q)}")
|
109 |
+
# logger.info(f"Wrong question data: {wrong_q}")
|
110 |
+
|
111 |
+
# # wrong_q๊ฐ ๋์
๋๋ฆฌ๊ฐ ์๋ ๊ฒฝ์ฐ ์ฒ๋ฆฌ
|
112 |
+
# if not isinstance(wrong_q, dict):
|
113 |
+
# logger.error(f"Invalid wrong_q type: {type(wrong_q)}")
|
114 |
+
# st.error("์ ์ฌ ๋ฌธ์ ์์ฑ์ ํ์ํ ๋ฐ์ดํฐ ํ์์ด ์๋ชป๋์์ต๋๋ค.")
|
115 |
+
# return None
|
116 |
+
|
117 |
+
# # misconception_id NaN ์ฒดํฌ
|
118 |
+
# if pd.isna(misconception_id):
|
119 |
+
# logger.warning("misconception_id ๊ฐ์ด NaN์
๋๋ค. ๊ธฐ๋ณธ ๋ฌธ์ ๋ฅผ ๋ฐํํฉ๋๋ค.")
|
120 |
+
# return {
|
121 |
+
# 'question': f"[์ ์ฌ ๋ฌธ์ ] {wrong_q.get('QuestionText', '๋ฌธ์ ๊ฐ ์ ๊ณต๋์ง ์์์ต๋๋ค.')}",
|
122 |
+
# 'choices': {
|
123 |
+
# 'A': "๋ณด๊ธฐ A",
|
124 |
+
# 'B': "๋ณด๊ธฐ B",
|
125 |
+
# 'C': "๋ณด๊ธฐ C",
|
126 |
+
# 'D': "๋ณด๊ธฐ D"
|
127 |
+
# },
|
128 |
+
# 'correct': 'A',
|
129 |
+
# 'explanation': "Misconception ID๊ฐ ์ ๊ณต๋์ง ์์ ๊ธฐ๋ณธ ๋ฌธ์ ๋ฅผ ๋ฐํํฉ๋๋ค."
|
130 |
+
# }
|
131 |
+
|
132 |
+
# try:
|
133 |
+
# # ์ ์ฌ ๋ฌธ์ ์์ฑ
|
134 |
+
# #logger.info(f"At least I'm in")
|
135 |
+
|
136 |
+
# #logger.info(f"Type of wrong_q: {type(wrong_q)}")
|
137 |
+
# #logger.info(f"Content of wrong_q: {wrong_q}")
|
138 |
+
# #logger.info(f"Type of misconception_id: {type(misconception_id)}")
|
139 |
+
# #logger.info(f"Value of misconception_id: {misconception_id}")
|
140 |
+
|
141 |
+
|
142 |
+
# # input ์ ๋ฆฌ
|
143 |
+
# construct_name=wrong_q['ConstructName'],
|
144 |
+
# subject_name=wrong_q['SubjectName'],
|
145 |
+
# question_text=wrong_q['QuestionText'],
|
146 |
+
# correct_answer_text=wrong_q[f'Answer{wrong_q["CorrectAnswer"]}Text'],
|
147 |
+
# wrong_answer_text=wrong_q[f'Answer{st.session_state.selected_wrong_answer}Text'],
|
148 |
+
# misconception_id=int(misconception_id)
|
149 |
+
# #logger.info(f"Input Arguments: construct_name={construct_name}, subject_name={subject_name}, question_text={question_text}, correct_answer_text={correct_answer_text}, wrong_answer_text={wrong_answer_text}, misconception_id={misconception_id}")
|
150 |
+
|
151 |
+
# construct_name = construct_name[0] if isinstance(construct_name, tuple) else construct_name
|
152 |
+
# subject_name = subject_name[0] if isinstance(subject_name, tuple) else subject_name
|
153 |
+
# question_text = question_text[0] if isinstance(question_text, tuple) else question_text
|
154 |
+
# correct_answer_text = correct_answer_text[0] if isinstance(correct_answer_text, tuple) else correct_answer_text
|
155 |
+
# wrong_answer_text = wrong_answer_text[0] if isinstance(wrong_answer_text, tuple) else wrong_answer_text
|
156 |
+
# #logger.info(f"construct_name={construct_name}, Type={type(construct_name)}, subject_name={subject_name}, Type={type(subject_name)}")
|
157 |
+
# #logger.info(f"question_text={question_text}, Type={type(question_text)}, correct_answer_text={correct_answer_text}, Type={type(correct_answer_text)}")
|
158 |
+
# #logger.info(f"wrong_answer_text={wrong_answer_text}, Type={type(wrong_answer_text)}")
|
159 |
+
# print("Debugging log block reached")
|
160 |
+
|
161 |
+
# #logger.info(f"Cleaned Input Arguments: construct_name={construct_name}, subject_name={subject_name}, question_text={question_text}, correct_answer_text={correct_answer_text}, wrong_answer_text={wrong_answer_text}, misconception_id={misconception_id}")
|
162 |
+
# #logger.debug(f"Cleaned arguments: {construct_name}, {subject_name}, {question_text}, {correct_answer_text}, {wrong_answer_text}, {misconception_id}")
|
163 |
+
|
164 |
+
# # generated_q, _ = generator.generate_similar_question_with_text(
|
165 |
+
# # construct_name=wrong_q['ConstructName'],
|
166 |
+
# # subject_name=wrong_q['SubjectName'],
|
167 |
+
# # question_text=wrong_q['QuestionText'],
|
168 |
+
# # correct_answer_text=wrong_q[f'Answer{wrong_q["CorrectAnswer"]}Text'],
|
169 |
+
# # wrong_answer_text=wrong_q[f'Answer{st.session_state.selected_wrong_answer}Text'],
|
170 |
+
# # misconception_id=int(misconception_id)
|
171 |
+
# # )
|
172 |
+
# logger.info(f"Inputs: construct_name={construct_name}, subject_name={subject_name}, question_text={question_text}, correct_answer_text={correct_answer_text}, wrong_answer_text={wrong_answer_text}, misconception_id={misconception_id}")
|
173 |
+
|
174 |
+
# generated_q, _ = generator.generate_similar_question_with_text(
|
175 |
+
# construct_name,
|
176 |
+
# subject_name,
|
177 |
+
# question_text,
|
178 |
+
# correct_answer_text,
|
179 |
+
# wrong_answer_text,
|
180 |
+
# misconception_id
|
181 |
+
# )
|
182 |
+
# logger.info(f"Generated question type: {type(generated_q)}")
|
183 |
+
|
184 |
+
# if generated_q:
|
185 |
+
# logger.info(f"At least there is something generated")
|
186 |
+
# return {
|
187 |
+
# 'question': generated_q.question,
|
188 |
+
# 'choices': generated_q.choices,
|
189 |
+
# 'correct': generated_q.correct_answer,
|
190 |
+
# 'explanation': generated_q.explanation
|
191 |
+
# }
|
192 |
+
# except Exception as e:
|
193 |
+
# # ๋๋ฒ๊น
์ ์ํ ์์ธ ์ค๋ฅ ์ถ๋ ฅ
|
194 |
+
# logger.error(f"Error generating similar question: {e}")
|
195 |
+
# st.error(f"๋ฌธ์ ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. {e}")
|
196 |
+
# return None
|
197 |
+
|
198 |
+
# # ๊ธฐ๋ณธ ๋ฌธ์ ๋ฐํ
|
199 |
+
# return {
|
200 |
+
# 'question': f"[์ ์ฌ ๋ฌธ์ ] {wrong_q.get('QuestionText', '๋ฌธ์ ๊ฐ ์ ๊ณต๋์ง ์์์ต๋๋ค.')}",
|
201 |
+
# 'choices': {
|
202 |
+
# 'A': "์๋ก์ด ๋ณด๊ธฐ A",
|
203 |
+
# 'B': "์๋ก์ด ๋ณด๊ธฐ B",
|
204 |
+
# 'C': "์๋ก์ด ๋ณด๊ธฐ C",
|
205 |
+
# 'D': "์๋ก์ด ๋ณด๊ธฐ D"
|
206 |
+
# },
|
207 |
+
# 'correct': 'A',
|
208 |
+
# 'explanation': f"์ด ๋ฌธ์ ๋ Misconception ID {misconception_id}์ ๊ด๋ จ๋์ด ์์ต๋๋ค."
|
209 |
+
# }
|
210 |
+
|
211 |
+
def generate_similar_question(wrong_q, misconception_id, generator):
|
212 |
+
"""์ ์ฌ ๋ฌธ์ ์์ฑ"""
|
213 |
+
logger.info(f"Generating similar question for misconception_id: {misconception_id}")
|
214 |
+
|
215 |
+
# ์
๋ ฅ ๋ฐ์ดํฐ ์ ํจ์ฑ ๊ฒ์ฌ
|
216 |
+
if not isinstance(wrong_q, dict):
|
217 |
+
logger.error(f"Invalid wrong_q type: {type(wrong_q)}")
|
218 |
+
st.error("์ ์ฌ ๋ฌธ์ ์์ฑ์ ํ์ํ ๋ฐ์ดํฐ ํ์์ด ์๋ชป๋์์ต๋๋ค.")
|
219 |
+
return None
|
220 |
+
|
221 |
+
# misconception_id๊ฐ ์ ํจํ์ง ํ์ธ
|
222 |
+
if pd.isna(misconception_id):
|
223 |
+
logger.warning("misconception_id is NaN")
|
224 |
+
return None
|
225 |
+
|
226 |
+
try:
|
227 |
+
# ๋ฐ์ดํฐ ์ค๋น (ํํ ๋ณํ ๋ฐฉ์ง)
|
228 |
+
input_data = {
|
229 |
+
'construct_name': str(wrong_q.get('ConstructName', '')),
|
230 |
+
'subject_name': str(wrong_q.get('SubjectName', '')),
|
231 |
+
'question_text': str(wrong_q.get('QuestionText', '')),
|
232 |
+
'correct_answer_text': str(wrong_q.get(f'Answer{wrong_q["CorrectAnswer"]}Text', '')),
|
233 |
+
'wrong_answer_text': str(wrong_q.get(f'Answer{st.session_state.selected_wrong_answer}Text', '')),
|
234 |
+
'misconception_id': int(misconception_id)
|
235 |
+
}
|
236 |
+
|
237 |
+
logger.info(f"Prepared input data: {input_data}")
|
238 |
+
|
239 |
+
# ์ ์ฌ ๋ฌธ์ ์์ฑ ํธ์ถ
|
240 |
+
generated_q, _ = generator.generate_similar_question_with_text(
|
241 |
+
construct_name=input_data['construct_name'],
|
242 |
+
subject_name=input_data['subject_name'],
|
243 |
+
question_text=input_data['question_text'],
|
244 |
+
correct_answer_text=input_data['correct_answer_text'],
|
245 |
+
wrong_answer_text=input_data['wrong_answer_text'],
|
246 |
+
misconception_id=input_data['misconception_id']
|
247 |
+
)
|
248 |
+
|
249 |
+
if generated_q:
|
250 |
+
return {
|
251 |
+
'question': generated_q.question,
|
252 |
+
'choices': generated_q.choices,
|
253 |
+
'correct': generated_q.correct_answer,
|
254 |
+
'explanation': generated_q.explanation
|
255 |
+
}
|
256 |
+
|
257 |
+
except Exception as e:
|
258 |
+
logger.error(f"Error in generate_similar_question: {str(e)}")
|
259 |
+
st.error(f"๋ฌธ์ ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}")
|
260 |
+
return None
|
261 |
+
|
262 |
+
return None
|
263 |
+
|
264 |
+
def handle_answer(answer, current_q):
|
265 |
+
"""๋ต๋ณ ์ฒ๋ฆฌ"""
|
266 |
+
if answer != current_q['CorrectAnswer']:
|
267 |
+
wrong_q_dict = current_q.to_dict()
|
268 |
+
st.session_state.wrong_questions.append(wrong_q_dict)
|
269 |
+
st.session_state.selected_wrong_answer = answer
|
270 |
+
|
271 |
+
misconception_key = f'Misconception{answer}Id'
|
272 |
+
misconception_id = current_q.get(misconception_key)
|
273 |
+
st.session_state.misconceptions.append(misconception_id)
|
274 |
+
|
275 |
+
st.session_state.current_question_index += 1
|
276 |
+
if st.session_state.current_question_index >= 10:
|
277 |
+
st.session_state.current_step = 'review'
|
278 |
+
|
279 |
+
def main():
|
280 |
+
"""๋ฉ์ธ ์ ํ๋ฆฌ์ผ์ด์
๋ก์ง"""
|
281 |
+
st.title("MisconcepTutor")
|
282 |
+
|
283 |
+
# Generator ์ด๊ธฐํ
|
284 |
+
generator = load_question_generator()
|
285 |
+
|
286 |
+
# ์ด๊ธฐ ํ๋ฉด
|
287 |
+
if st.session_state.current_step == 'initial':
|
288 |
+
st.write("#### ํ์ต์ ์์ํ๊ฒ ์ต๋๋ค. 10๊ฐ์ ๋ฌธ์ ๋ฅผ ํ์ด๋ณผ๊น์?")
|
289 |
+
if st.button("ํ์ต ์์", key="start_quiz"):
|
290 |
+
start_quiz()
|
291 |
+
st.rerun()
|
292 |
+
|
293 |
+
# ํด์ฆ ํ๋ฉด
|
294 |
+
elif st.session_state.current_step == 'quiz':
|
295 |
+
current_q = st.session_state.questions.iloc[st.session_state.current_question_index]
|
296 |
+
|
297 |
+
# ์งํ ์ํฉ ํ์
|
298 |
+
progress = st.session_state.current_question_index / 10
|
299 |
+
st.progress(progress)
|
300 |
+
st.write(f"### ๋ฌธ์ {st.session_state.current_question_index + 1}/10")
|
301 |
+
|
302 |
+
# ๋ฌธ์ ํ์
|
303 |
+
st.markdown("---")
|
304 |
+
st.write(current_q['QuestionText'])
|
305 |
+
|
306 |
+
# ๋ณด๊ธฐ ํ์
|
307 |
+
col1, col2 = st.columns(2)
|
308 |
+
with col1:
|
309 |
+
if st.button(f"A) {current_q['AnswerAText']}", key="A"):
|
310 |
+
handle_answer('A', current_q)
|
311 |
+
st.rerun()
|
312 |
+
if st.button(f"C) {current_q['AnswerCText']}", key="C"):
|
313 |
+
handle_answer('C', current_q)
|
314 |
+
st.rerun()
|
315 |
+
with col2:
|
316 |
+
if st.button(f"B) {current_q['AnswerBText']}", key="B"):
|
317 |
+
handle_answer('B', current_q)
|
318 |
+
st.rerun()
|
319 |
+
if st.button(f"D) {current_q['AnswerDText']}", key="D"):
|
320 |
+
handle_answer('D', current_q)
|
321 |
+
st.rerun()
|
322 |
+
|
323 |
+
# ๋ณต์ต ํ๋ฉด
|
324 |
+
elif st.session_state.current_step == 'review':
|
325 |
+
st.write("### ํ์ต ๊ฒฐ๊ณผ")
|
326 |
+
|
327 |
+
# ๊ฒฐ๊ณผ ํต๊ณ
|
328 |
+
col1, col2, col3 = st.columns(3)
|
329 |
+
col1.metric("์ด ๋ฌธ์ ์", 10)
|
330 |
+
col2.metric("๋ง์ ๋ฌธ์ ", 10 - len(st.session_state.wrong_questions))
|
331 |
+
col3.metric("ํ๋ฆฐ ๋ฌธ์ ", len(st.session_state.wrong_questions))
|
332 |
+
|
333 |
+
# ๊ฒฐ๊ณผ์ ๋ฐ๋ฅธ ๋ฉ์์ง ํ์
|
334 |
+
if len(st.session_state.wrong_questions) == 0:
|
335 |
+
st.balloons() # ์ถํ ํจ๊ณผ
|
336 |
+
st.success("๐ ์ถํํฉ๋๋ค! ๋ชจ๋ ๋ฌธ์ ๋ฅผ ๋ง์ถ์
จ์ด์!")
|
337 |
+
st.markdown("""
|
338 |
+
### ๐ ์ํ์์ด์ญ๋๋ค!
|
339 |
+
์๋ฒฝํ ์ ์๋ฅผ ๋ฐ์ผ์
จ๋ค์! ์ํ์ ๊ฐ๋
์ ์ ํํ๊ฒ ์ดํดํ๊ณ ๊ณ์ ๊ฒ ๊ฐ์ต๏ฟฝ๏ฟฝ๋ค.
|
340 |
+
""")
|
341 |
+
elif len(st.session_state.wrong_questions) <= 3:
|
342 |
+
st.success("์ ํ์
จ์ด์! ์กฐ๊ธ๋ง ๋ ์ฐ์ตํ๋ฉด ์๋ฒฝํ ๊ฑฐ์์!")
|
343 |
+
else:
|
344 |
+
st.info("์ฒ์ฒํ ๊ฐ๋
์ ๋ณต์ตํด๋ณด์์. ์ฐ์ตํ๋ค ๋ณด๋ฉด ๋์ด๋ ๊ฑฐ์์!")
|
345 |
+
|
346 |
+
# ๋ค๋น๊ฒ์ด์
๋ฒํผ
|
347 |
+
col1, col2 = st.columns(2)
|
348 |
+
with col1:
|
349 |
+
if st.button("๐ ์๋ก์ด ๋ฌธ์ ์ธํธ ์์ํ๊ธฐ", use_container_width=True):
|
350 |
+
start_quiz()
|
351 |
+
st.rerun()
|
352 |
+
with col2:
|
353 |
+
if st.button("๐ ์ฒ์์ผ๋ก ๋์๊ฐ๊ธฐ", use_container_width=True):
|
354 |
+
st.session_state.clear()
|
355 |
+
st.rerun()
|
356 |
+
|
357 |
+
# ํ๋ฆฐ ๋ฌธ์ ๋ถ์
|
358 |
+
if st.session_state.wrong_questions:
|
359 |
+
st.write("### โ๏ธ ํ๋ฆฐ ๋ฌธ์ ๋ถ์")
|
360 |
+
for i, (wrong_q, misconception_id) in enumerate(zip(
|
361 |
+
st.session_state.wrong_questions,
|
362 |
+
st.session_state.misconceptions
|
363 |
+
)):
|
364 |
+
with st.expander(f"๐ ํ๋ฆฐ ๋ฌธ์ #{i + 1}"):
|
365 |
+
st.write("**๐ ๋ฌธ์ :**")
|
366 |
+
st.write(wrong_q['QuestionText'])
|
367 |
+
st.write("**โ
์ ๋ต:**", wrong_q['CorrectAnswer'])
|
368 |
+
|
369 |
+
st.write("---")
|
370 |
+
st.write("**๐ ๊ด๋ จ๋ Misconception:**")
|
371 |
+
if misconception_id and not pd.isna(misconception_id):
|
372 |
+
misconception_text = generator.get_misconception_text(misconception_id)
|
373 |
+
st.info(f"Misconception ID: {int(misconception_id)}\n\n{misconception_text}")
|
374 |
+
else:
|
375 |
+
st.info("Misconception ์ ๋ณด๊ฐ ์์ต๋๋ค.")
|
376 |
+
# try:
|
377 |
+
# misconception_text = generator.get_misconception_text(misconception_id)
|
378 |
+
# st.info(f"Misconception ID: {int(misconception_id)}\n\n{misconception_text}")
|
379 |
+
# except Exception as e:
|
380 |
+
# logger.error(f"Error in get_misconception_text: {e}")
|
381 |
+
# st.info("Misconception ์ ๋ณด๊ฐ ์์ต๋๋ค.")
|
382 |
+
# return None, None
|
383 |
+
|
384 |
+
# ์ ์ฌ ๋ฌธ์ ์์ฑ ๋ฒํผ
|
385 |
+
if st.button(f"๐ ์ ์ฌ ๋ฌธ์ ํ๊ธฐ #{i + 1}", key=f"retry_{i}"):
|
386 |
+
with st.spinner("์ ์ฌ ๋ฌธ์ ๋ฅผ ์์ฑํ๊ณ ์์ต๋๋ค..."):
|
387 |
+
logger.info(f"Generating similar question for misconception_id: {misconception_id}")
|
388 |
+
new_question = generate_similar_question(wrong_q, misconception_id, generator)
|
389 |
+
if new_question:
|
390 |
+
st.write("### ๐ฏ ์ ์ฌ ๋ฌธ์ ")
|
391 |
+
st.write(new_question['question'])
|
392 |
+
st.write("**๋ณด๊ธฐ:**")
|
393 |
+
for choice, text in new_question['choices'].items():
|
394 |
+
st.write(f"{choice}) {text}")
|
395 |
+
st.write("**โ
์ ๋ต:**", new_question['correct'])
|
396 |
+
st.write("**๐ ํด์ค:**", new_question['explanation'])
|
397 |
+
else:
|
398 |
+
st.error("์ ์ฌ ๋ฌธ์ ๋ฅผ ์์ฑํ ์ ์์ต๋๋ค.")
|
399 |
+
if __name__ == "__main__":
|
400 |
+
main()
|
401 |
+
|
402 |
+
# random_state 42์์ ์ ๋ต
|
403 |
+
# D C A A C
|
404 |
+
# A B B B B
|