Jintonic92 commited on
Commit
6085a05
ยท
verified ยท
1 Parent(s): 67d16a2

Upload MisconceptTutor.py

Browse files
Files changed (1) hide show
  1. 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