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