File size: 18,504 Bytes
6085a05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
import streamlit as st
import pandas as pd
import os
from src.SecondModule.module2 import SimilarQuestionGenerator
import logging
from typing import Optional, Tuple
logging.basicConfig(level=logging.DEBUG)


# Streamlit ํŽ˜์ด์ง€ ๊ธฐ๋ณธ ์„ค์ •
st.set_page_config(
    page_title="MisconcepTutor", 
    layout="wide", 
    initial_sidebar_state="expanded"
)

# ๊ฒฝ๋กœ ์„ค์ •
base_path = os.path.dirname(os.path.abspath(__file__))
data_path = os.path.join(base_path, 'Data')
misconception_csv_path = os.path.join(data_path, 'misconception_mapping.csv')

# ๋กœ๊น… ์„ค์ •
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# ์„ธ์…˜ ์ƒํƒœ ์ดˆ๊ธฐํ™” - ๊ฐ€์žฅ ๋จผ์ € ์‹คํ–‰๋˜๋„๋ก ์ตœ์ƒ๋‹จ์— ๋ฐฐ์น˜
if 'initialized' not in st.session_state:
    st.session_state.initialized = True
    st.session_state.wrong_questions = []
    st.session_state.misconceptions = []
    st.session_state.current_question_index = 0
    st.session_state.generated_questions = []
    st.session_state.current_step = 'initial'
    st.session_state.selected_wrong_answer = None
    st.session_state.questions = []
    logger.info("Session state initialized")

# ๋ฌธ์ œ ์ƒ์„ฑ๊ธฐ ์ดˆ๊ธฐํ™”
@st.cache_resource
def load_question_generator():
    """๋ฌธ์ œ ์ƒ์„ฑ ๋ชจ๋ธ ๋กœ๋“œ"""
    if not os.path.exists(misconception_csv_path):
        st.error(f"CSV ํŒŒ์ผ์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค: {misconception_csv_path}")
        raise FileNotFoundError(f"CSV ํŒŒ์ผ์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค: {misconception_csv_path}")
    return SimilarQuestionGenerator(misconception_csv_path=misconception_csv_path)

# CSV ๋ฐ์ดํ„ฐ ๋กœ๋“œ ํ•จ์ˆ˜
@st.cache_data
def load_data(data_file = '/train.csv'):
    try:
        file_path = os.path.join(data_path, data_file.lstrip('/'))
        df = pd.read_csv(file_path)
        logger.info(f"Data loaded successfully from {file_path}")
        return df
    except FileNotFoundError:
        st.error(f"ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค: {data_file}")
        logger.error(f"File not found: {data_file}")
        return None

def start_quiz():
    """ํ€ด์ฆˆ ์‹œ์ž‘ ๋ฐ ์ดˆ๊ธฐํ™”"""
    df = load_data()
    if df is None or df.empty:
        st.error("๋ฐ์ดํ„ฐ๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋ฐ์ดํ„ฐ์…‹์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”.")
        return

    st.session_state.questions = df.sample(n=10, random_state=42)
    st.session_state.current_step = 'quiz'
    st.session_state.current_question_index = 0
    st.session_state.wrong_questions = []
    st.session_state.misconceptions = []
    st.session_state.generated_questions = []
    logger.info("Quiz started")

# def generate_similar_question(wrong_q, misconception_id, generator):
#     """์œ ์‚ฌ ๋ฌธ์ œ ์ƒ์„ฑ"""
#     if not isinstance(wrong_q, dict):
#         logger.error(f"Invalid wrong_q type: {type(wrong_q)}")
#         st.error("์œ ์‚ฌ ๋ฌธ์ œ ์ƒ์„ฑ์— ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ ํ˜•์‹์ด ์ž˜๋ชป๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
#         return None

#     try:
#         generated_q, _ = generator.generate_similar_question_with_text(
#             construct_name=wrong_q['ConstructName'],
#             subject_name=wrong_q['SubjectName'],
#             question_text=wrong_q['QuestionText'],
#             correct_answer_text=wrong_q[f'Answer{wrong_q["CorrectAnswer"]}Text'],
#             wrong_answer_text=wrong_q[f'Answer{st.session_state.selected_wrong_answer}Text'],
#             misconception_id=misconception_id
#         )
        
#         if generated_q:
#             return {
#                 'question': generated_q.question,
#                 'choices': generated_q.choices,
#                 'correct': generated_q.correct_answer,
#                 'explanation': generated_q.explanation
#             }
#     except Exception as e:
#         logger.error(f"Error generating similar question: {e}")
#         st.error(f"๋ฌธ์ œ ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.")
#         return None

# def generate_similar_question(wrong_q, misconception_id, generator):
#     """์œ ์‚ฌ ๋ฌธ์ œ ์ƒ์„ฑ"""
#     # ์ž…๋ ฅ ๋ฐ์ดํ„ฐ ํ™•์ธ
#     logger.info(f"Generating similar question for misconception_id: {misconception_id}")
#     logger.info(f"Wrong question data type: {type(wrong_q)}")
#     logger.info(f"Wrong question data: {wrong_q}")

#     # wrong_q๊ฐ€ ๋”•์…”๋„ˆ๋ฆฌ๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ ์ฒ˜๋ฆฌ
#     if not isinstance(wrong_q, dict):
#         logger.error(f"Invalid wrong_q type: {type(wrong_q)}")
#         st.error("์œ ์‚ฌ ๋ฌธ์ œ ์ƒ์„ฑ์— ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ ํ˜•์‹์ด ์ž˜๋ชป๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
#         return None

#     # misconception_id NaN ์ฒดํฌ
#     if pd.isna(misconception_id):
#         logger.warning("misconception_id ๊ฐ’์ด NaN์ž…๋‹ˆ๋‹ค. ๊ธฐ๋ณธ ๋ฌธ์ œ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.")
#         return {
#             'question': f"[์œ ์‚ฌ ๋ฌธ์ œ] {wrong_q.get('QuestionText', '๋ฌธ์ œ๊ฐ€ ์ œ๊ณต๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.')}",
#             'choices': {
#                 'A': "๋ณด๊ธฐ A",
#                 'B': "๋ณด๊ธฐ B",
#                 'C': "๋ณด๊ธฐ C",
#                 'D': "๋ณด๊ธฐ D"
#             },
#             'correct': 'A',
#             'explanation': "Misconception ID๊ฐ€ ์ œ๊ณต๋˜์ง€ ์•Š์•„ ๊ธฐ๋ณธ ๋ฌธ์ œ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค."
#         }

#     try:
#         # ์œ ์‚ฌ ๋ฌธ์ œ ์ƒ์„ฑ
#         #logger.info(f"At least I'm in")

#         #logger.info(f"Type of wrong_q: {type(wrong_q)}")
#         #logger.info(f"Content of wrong_q: {wrong_q}")
#         #logger.info(f"Type of misconception_id: {type(misconception_id)}")
#         #logger.info(f"Value of misconception_id: {misconception_id}")


#         # input ์ •๋ฆฌ 
#         construct_name=wrong_q['ConstructName'],
#         subject_name=wrong_q['SubjectName'],
#         question_text=wrong_q['QuestionText'],
#         correct_answer_text=wrong_q[f'Answer{wrong_q["CorrectAnswer"]}Text'],
#         wrong_answer_text=wrong_q[f'Answer{st.session_state.selected_wrong_answer}Text'],
#         misconception_id=int(misconception_id)
#         #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}")
        
#         construct_name = construct_name[0] if isinstance(construct_name, tuple) else construct_name
#         subject_name = subject_name[0] if isinstance(subject_name, tuple) else subject_name
#         question_text = question_text[0] if isinstance(question_text, tuple) else question_text
#         correct_answer_text = correct_answer_text[0] if isinstance(correct_answer_text, tuple) else correct_answer_text
#         wrong_answer_text = wrong_answer_text[0] if isinstance(wrong_answer_text, tuple) else wrong_answer_text
#         #logger.info(f"construct_name={construct_name}, Type={type(construct_name)}, subject_name={subject_name}, Type={type(subject_name)}")
#         #logger.info(f"question_text={question_text}, Type={type(question_text)}, correct_answer_text={correct_answer_text}, Type={type(correct_answer_text)}")
#         #logger.info(f"wrong_answer_text={wrong_answer_text}, Type={type(wrong_answer_text)}")
#         print("Debugging log block reached")

#         #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}")
#         #logger.debug(f"Cleaned arguments: {construct_name}, {subject_name}, {question_text}, {correct_answer_text}, {wrong_answer_text}, {misconception_id}")

#         # generated_q, _ = generator.generate_similar_question_with_text(
#         #     construct_name=wrong_q['ConstructName'],
#         #     subject_name=wrong_q['SubjectName'],
#         #     question_text=wrong_q['QuestionText'],
#         #     correct_answer_text=wrong_q[f'Answer{wrong_q["CorrectAnswer"]}Text'],
#         #     wrong_answer_text=wrong_q[f'Answer{st.session_state.selected_wrong_answer}Text'],
#         #     misconception_id=int(misconception_id)
#         # )
#         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}")

#         generated_q, _ = generator.generate_similar_question_with_text(
#             construct_name,
#             subject_name,
#             question_text,
#             correct_answer_text,
#             wrong_answer_text,
#             misconception_id
#         )
#         logger.info(f"Generated question type: {type(generated_q)}")

#         if generated_q: 
#             logger.info(f"At least there is something generated")       
#             return {
#                 'question': generated_q.question,
#                 'choices': generated_q.choices,
#                 'correct': generated_q.correct_answer,
#                 'explanation': generated_q.explanation
#             }
#     except Exception as e:
#         # ๋””๋ฒ„๊น…์„ ์œ„ํ•œ ์ƒ์„ธ ์˜ค๋ฅ˜ ์ถœ๋ ฅ
#         logger.error(f"Error generating similar question: {e}")
#         st.error(f"๋ฌธ์ œ ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. {e}")
#         return None

#     # ๊ธฐ๋ณธ ๋ฌธ์ œ ๋ฐ˜ํ™˜
#     return {
#         'question': f"[์œ ์‚ฌ ๋ฌธ์ œ] {wrong_q.get('QuestionText', '๋ฌธ์ œ๊ฐ€ ์ œ๊ณต๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.')}",
#         'choices': {
#             'A': "์ƒˆ๋กœ์šด ๋ณด๊ธฐ A",
#             'B': "์ƒˆ๋กœ์šด ๋ณด๊ธฐ B",
#             'C': "์ƒˆ๋กœ์šด ๋ณด๊ธฐ C",
#             'D': "์ƒˆ๋กœ์šด ๋ณด๊ธฐ D"
#         },
#         'correct': 'A',
#         'explanation': f"์ด ๋ฌธ์ œ๋Š” Misconception ID {misconception_id}์™€ ๊ด€๋ จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค."
#     }

def generate_similar_question(wrong_q, misconception_id, generator):
    """์œ ์‚ฌ ๋ฌธ์ œ ์ƒ์„ฑ"""
    logger.info(f"Generating similar question for misconception_id: {misconception_id}")
    
    # ์ž…๋ ฅ ๋ฐ์ดํ„ฐ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ
    if not isinstance(wrong_q, dict):
        logger.error(f"Invalid wrong_q type: {type(wrong_q)}")
        st.error("์œ ์‚ฌ ๋ฌธ์ œ ์ƒ์„ฑ์— ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ ํ˜•์‹์ด ์ž˜๋ชป๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
        return None
        
    # misconception_id๊ฐ€ ์œ ํšจํ•œ์ง€ ํ™•์ธ
    if pd.isna(misconception_id):
        logger.warning("misconception_id is NaN")
        return None
        
    try:
        # ๋ฐ์ดํ„ฐ ์ค€๋น„ (ํŠœํ”Œ ๋ณ€ํ™˜ ๋ฐฉ์ง€)
        input_data = {
            'construct_name': str(wrong_q.get('ConstructName', '')),
            'subject_name': str(wrong_q.get('SubjectName', '')),
            'question_text': str(wrong_q.get('QuestionText', '')),
            'correct_answer_text': str(wrong_q.get(f'Answer{wrong_q["CorrectAnswer"]}Text', '')),
            'wrong_answer_text': str(wrong_q.get(f'Answer{st.session_state.selected_wrong_answer}Text', '')),
            'misconception_id': int(misconception_id)
        }
        
        logger.info(f"Prepared input data: {input_data}")
        
        # ์œ ์‚ฌ ๋ฌธ์ œ ์ƒ์„ฑ ํ˜ธ์ถœ
        generated_q, _ = generator.generate_similar_question_with_text(
            construct_name=input_data['construct_name'],
            subject_name=input_data['subject_name'],
            question_text=input_data['question_text'],
            correct_answer_text=input_data['correct_answer_text'],
            wrong_answer_text=input_data['wrong_answer_text'],
            misconception_id=input_data['misconception_id']
        )
        
        if generated_q:
            return {
                'question': generated_q.question,
                'choices': generated_q.choices,
                'correct': generated_q.correct_answer,
                'explanation': generated_q.explanation
            }
            
    except Exception as e:
        logger.error(f"Error in generate_similar_question: {str(e)}")
        st.error(f"๋ฌธ์ œ ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}")
        return None

    return None

def handle_answer(answer, current_q):
    """๋‹ต๋ณ€ ์ฒ˜๋ฆฌ"""
    if answer != current_q['CorrectAnswer']:
        wrong_q_dict = current_q.to_dict()
        st.session_state.wrong_questions.append(wrong_q_dict)
        st.session_state.selected_wrong_answer = answer
        
        misconception_key = f'Misconception{answer}Id'
        misconception_id = current_q.get(misconception_key)
        st.session_state.misconceptions.append(misconception_id)
    
    st.session_state.current_question_index += 1
    if st.session_state.current_question_index >= 10:
        st.session_state.current_step = 'review'

def main():
    """๋ฉ”์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋กœ์ง"""
    st.title("MisconcepTutor")
    
    # Generator ์ดˆ๊ธฐํ™”
    generator = load_question_generator()

    # ์ดˆ๊ธฐ ํ™”๋ฉด
    if st.session_state.current_step == 'initial':
        st.write("#### ํ•™์Šต์„ ์‹œ์ž‘ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. 10๊ฐœ์˜ ๋ฌธ์ œ๋ฅผ ํ’€์–ด๋ณผ๊นŒ์š”?")
        if st.button("ํ•™์Šต ์‹œ์ž‘", key="start_quiz"):
            start_quiz()
            st.rerun()

    # ํ€ด์ฆˆ ํ™”๋ฉด
    elif st.session_state.current_step == 'quiz':
        current_q = st.session_state.questions.iloc[st.session_state.current_question_index]
        
        # ์ง„ํ–‰ ์ƒํ™ฉ ํ‘œ์‹œ
        progress = st.session_state.current_question_index / 10
        st.progress(progress)
        st.write(f"### ๋ฌธ์ œ {st.session_state.current_question_index + 1}/10")
        
        # ๋ฌธ์ œ ํ‘œ์‹œ
        st.markdown("---")
        st.write(current_q['QuestionText'])
        
        # ๋ณด๊ธฐ ํ‘œ์‹œ
        col1, col2 = st.columns(2)
        with col1:
            if st.button(f"A) {current_q['AnswerAText']}", key="A"):
                handle_answer('A', current_q)
                st.rerun()
            if st.button(f"C) {current_q['AnswerCText']}", key="C"):
                handle_answer('C', current_q)
                st.rerun()
        with col2:
            if st.button(f"B) {current_q['AnswerBText']}", key="B"):
                handle_answer('B', current_q)
                st.rerun()
            if st.button(f"D) {current_q['AnswerDText']}", key="D"):
                handle_answer('D', current_q)
                st.rerun()

    # ๋ณต์Šต ํ™”๋ฉด
    elif st.session_state.current_step == 'review':
        st.write("### ํ•™์Šต ๊ฒฐ๊ณผ")
        
        # ๊ฒฐ๊ณผ ํ†ต๊ณ„
        col1, col2, col3 = st.columns(3)
        col1.metric("์ด ๋ฌธ์ œ ์ˆ˜", 10)
        col2.metric("๋งž์€ ๋ฌธ์ œ", 10 - len(st.session_state.wrong_questions))
        col3.metric("ํ‹€๋ฆฐ ๋ฌธ์ œ", len(st.session_state.wrong_questions))
        
        # ๊ฒฐ๊ณผ์— ๋”ฐ๋ฅธ ๋ฉ”์‹œ์ง€ ํ‘œ์‹œ
        if len(st.session_state.wrong_questions) == 0:
            st.balloons()  # ์ถ•ํ•˜ ํšจ๊ณผ
            st.success("๐ŸŽ‰ ์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค! ๋ชจ๋“  ๋ฌธ์ œ๋ฅผ ๋งž์ถ”์…จ์–ด์š”!")
            st.markdown("""
            ### ๐Ÿ† ์ˆ˜ํ•™์™•์ด์‹ญ๋‹ˆ๋‹ค! 
            ์™„๋ฒฝํ•œ ์ ์ˆ˜๋ฅผ ๋ฐ›์œผ์…จ๋„ค์š”! ์ˆ˜ํ•™์  ๊ฐœ๋…์„ ์ •ํ™•ํ•˜๊ฒŒ ์ดํ•ดํ•˜๊ณ  ๊ณ„์‹  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
            """)
        elif len(st.session_state.wrong_questions) <= 3:
            st.success("์ž˜ ํ•˜์…จ์–ด์š”! ์กฐ๊ธˆ๋งŒ ๋” ์—ฐ์Šตํ•˜๋ฉด ์™„๋ฒฝํ•  ๊ฑฐ์˜ˆ์š”!")
        else:
            st.info("์ฒœ์ฒœํžˆ ๊ฐœ๋…์„ ๋ณต์Šตํ•ด๋ณด์•„์š”. ์—ฐ์Šตํ•˜๋‹ค ๋ณด๋ฉด ๋Š˜์–ด๋‚  ๊ฑฐ์˜ˆ์š”!")
        
        # ๋„ค๋น„๊ฒŒ์ด์…˜ ๋ฒ„ํŠผ
        col1, col2 = st.columns(2)
        with col1:
            if st.button("๐Ÿ”„ ์ƒˆ๋กœ์šด ๋ฌธ์ œ ์„ธํŠธ ์‹œ์ž‘ํ•˜๊ธฐ", use_container_width=True):
                start_quiz()
                st.rerun()
        with col2:
            if st.button("๐Ÿ  ์ฒ˜์Œ์œผ๋กœ ๋Œ์•„๊ฐ€๊ธฐ", use_container_width=True):
                st.session_state.clear()
                st.rerun()
        
        # ํ‹€๋ฆฐ ๋ฌธ์ œ ๋ถ„์„
        if st.session_state.wrong_questions:
            st.write("### โœ๏ธ ํ‹€๋ฆฐ ๋ฌธ์ œ ๋ถ„์„")
            for i, (wrong_q, misconception_id) in enumerate(zip(
                st.session_state.wrong_questions,
                st.session_state.misconceptions
            )):
                with st.expander(f"๐Ÿ“ ํ‹€๋ฆฐ ๋ฌธ์ œ #{i + 1}"):
                    st.write("**๐Ÿ“‹ ๋ฌธ์ œ:**")
                    st.write(wrong_q['QuestionText'])
                    st.write("**โœ… ์ •๋‹ต:**", wrong_q['CorrectAnswer'])
                    
                    st.write("---")
                    st.write("**๐Ÿ” ๊ด€๋ จ๋œ Misconception:**")
                    if misconception_id and not pd.isna(misconception_id):
                        misconception_text = generator.get_misconception_text(misconception_id)
                        st.info(f"Misconception ID: {int(misconception_id)}\n\n{misconception_text}")
                    else:
                        st.info("Misconception ์ •๋ณด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.")
                    # try:
                    #     misconception_text = generator.get_misconception_text(misconception_id)
                    #     st.info(f"Misconception ID: {int(misconception_id)}\n\n{misconception_text}")
                    # except Exception as e:
                    #     logger.error(f"Error in get_misconception_text: {e}")
                    #     st.info("Misconception ์ •๋ณด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.")
                    #     return None, None
                    
                    # ์œ ์‚ฌ ๋ฌธ์ œ ์ƒ์„ฑ ๋ฒ„ํŠผ
                    if st.button(f"๐Ÿ“š ์œ ์‚ฌ ๋ฌธ์ œ ํ’€๊ธฐ #{i + 1}", key=f"retry_{i}"):
                        with st.spinner("์œ ์‚ฌ ๋ฌธ์ œ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค..."):
                            logger.info(f"Generating similar question for misconception_id: {misconception_id}")
                            new_question = generate_similar_question(wrong_q, misconception_id, generator)
                            if new_question:
                                st.write("### ๐ŸŽฏ ์œ ์‚ฌ ๋ฌธ์ œ")
                                st.write(new_question['question'])
                                st.write("**๋ณด๊ธฐ:**")
                                for choice, text in new_question['choices'].items():
                                    st.write(f"{choice}) {text}")
                                st.write("**โœ… ์ •๋‹ต:**", new_question['correct'])
                                st.write("**๐Ÿ“ ํ•ด์„ค:**", new_question['explanation'])
                            else:
                                st.error("์œ ์‚ฌ ๋ฌธ์ œ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
if __name__ == "__main__":
    main()

# random_state 42์—์„œ ์ •๋‹ต
    # D C A A C
    # A B B B B