Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,8 @@ from src.SecondModule.module2 import SimilarQuestionGenerator
|
|
6 |
from src.ThirdModule.module3 import AnswerVerifier
|
7 |
import logging
|
8 |
from typing import Optional, Tuple
|
9 |
-
from
|
|
|
10 |
|
11 |
logging.basicConfig(level=logging.DEBUG)
|
12 |
|
@@ -41,7 +42,7 @@ misconception_csv_path = os.path.join(data_path, 'misconception_mapping.csv')
|
|
41 |
logging.basicConfig(level=logging.INFO)
|
42 |
logger = logging.getLogger(__name__)
|
43 |
|
44 |
-
# ์ธ์
์ํ ์ด๊ธฐํ
|
45 |
if 'initialized' not in st.session_state:
|
46 |
st.session_state.initialized = True
|
47 |
st.session_state.wrong_questions = []
|
@@ -53,6 +54,7 @@ if 'initialized' not in st.session_state:
|
|
53 |
st.session_state.questions = []
|
54 |
logger.info("Session state initialized")
|
55 |
|
|
|
56 |
# ๋ฌธ์ ์์ฑ๊ธฐ ์ด๊ธฐํ
|
57 |
@st.cache_resource
|
58 |
def load_question_generator():
|
@@ -90,28 +92,214 @@ def start_quiz():
|
|
90 |
st.session_state.generated_questions = []
|
91 |
logger.info("Quiz started")
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
def handle_answer(answer, current_q):
|
94 |
"""๋ต๋ณ ์ฒ๋ฆฌ"""
|
95 |
if answer != current_q['CorrectAnswer']:
|
96 |
wrong_q_dict = current_q.to_dict()
|
97 |
st.session_state.wrong_questions.append(wrong_q_dict)
|
98 |
st.session_state.selected_wrong_answer = answer
|
99 |
-
|
100 |
misconception_key = f'Misconception{answer}Id'
|
101 |
misconception_id = current_q.get(misconception_key)
|
102 |
st.session_state.misconceptions.append(misconception_id)
|
103 |
-
|
104 |
st.session_state.current_question_index += 1
|
105 |
-
if st.session_state.current_question_index >=
|
106 |
st.session_state.current_step = 'review'
|
|
|
|
|
107 |
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
-
def display_math_content(content: str):
|
112 |
-
"""์ํ ๋ด์ฉ์ ํ๋ฉด์ ํ์"""
|
113 |
-
formatted_content = latex_formatter.format_expression(content)
|
114 |
-
st.markdown(formatted_content, unsafe_allow_html=True)
|
115 |
|
116 |
def main():
|
117 |
"""๋ฉ์ธ ์ ํ๋ฆฌ์ผ์ด์
๋ก์ง"""
|
@@ -120,6 +308,10 @@ def main():
|
|
120 |
# Misconception Model ๋ก๋
|
121 |
misconception_model = load_misconception_model()
|
122 |
|
|
|
|
|
|
|
|
|
123 |
# ์ด๊ธฐ ํ๋ฉด
|
124 |
if st.session_state.current_step == 'initial':
|
125 |
st.write("#### ํ์ต์ ์์ํ๊ฒ ์ต๋๋ค. 10๊ฐ์ ๋ฌธ์ ๋ฅผ ํ์ด๋ณผ๊น์?")
|
@@ -130,64 +322,174 @@ def main():
|
|
130 |
# ํด์ฆ ํ๋ฉด
|
131 |
elif st.session_state.current_step == 'quiz':
|
132 |
current_q = st.session_state.questions.iloc[st.session_state.current_question_index]
|
133 |
-
|
134 |
# ์งํ ์ํฉ ํ์
|
135 |
progress = st.session_state.current_question_index / 10
|
136 |
st.progress(progress)
|
137 |
st.write(f"### ๋ฌธ์ {st.session_state.current_question_index + 1}/10")
|
138 |
-
|
139 |
# ๋ฌธ์ ํ์
|
140 |
st.markdown("---")
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
if st.button(latex_formatter.format_expression(f"B) {current_q['AnswerBText']}"), key="B"):
|
154 |
-
handle_answer('B', current_q)
|
155 |
-
st.rerun()
|
156 |
-
if st.button(latex_formatter.format_expression(f"D) {current_q['AnswerDText']}"), key="D"):
|
157 |
-
handle_answer('D', current_q)
|
158 |
-
st.rerun()
|
159 |
|
160 |
# ๋ณต์ต ํ๋ฉด
|
161 |
elif st.session_state.current_step == 'review':
|
162 |
st.write("### ํ์ต ๊ฒฐ๊ณผ")
|
163 |
-
|
164 |
# ๊ฒฐ๊ณผ ํต๊ณ
|
165 |
col1, col2, col3 = st.columns(3)
|
166 |
col1.metric("์ด ๋ฌธ์ ์", 10)
|
167 |
col2.metric("๋ง์ ๋ฌธ์ ", 10 - len(st.session_state.wrong_questions))
|
168 |
col3.metric("ํ๋ฆฐ ๋ฌธ์ ", len(st.session_state.wrong_questions))
|
169 |
-
|
170 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
if st.session_state.wrong_questions:
|
172 |
st.write("### โ๏ธ ํ๋ฆฐ ๋ฌธ์ ๋ถ์")
|
173 |
tabs = st.tabs([f"๐ ํ๋ฆฐ ๋ฌธ์ #{i + 1}" for i in range(len(st.session_state.wrong_questions))])
|
174 |
-
|
175 |
for i, (tab, (wrong_q, misconception_id)) in enumerate(zip(
|
176 |
tabs,
|
177 |
zip(st.session_state.wrong_questions, st.session_state.misconceptions)
|
178 |
)):
|
179 |
with tab:
|
180 |
st.write("**๐ ๋ฌธ์ :**")
|
181 |
-
|
182 |
-
st.write("**โ
์ ๋ต:**"
|
|
|
183 |
|
184 |
st.write("---")
|
185 |
st.write("**๐ ๊ด๋ จ๋ Misconception:**")
|
186 |
if misconception_id and not pd.isna(misconception_id):
|
187 |
-
misconception_text =
|
188 |
st.info(f"Misconception ID: {int(misconception_id)}\n\n{misconception_text}")
|
189 |
else:
|
190 |
st.info("Misconception ์ ๋ณด๊ฐ ์์ต๋๋ค.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
|
192 |
if __name__ == "__main__":
|
193 |
main()
|
|
|
|
|
|
|
|
|
|
|
|
6 |
from src.ThirdModule.module3 import AnswerVerifier
|
7 |
import logging
|
8 |
from typing import Optional, Tuple
|
9 |
+
from pylatexenc.latex2text import LatexNodes2Text
|
10 |
+
import re
|
11 |
|
12 |
logging.basicConfig(level=logging.DEBUG)
|
13 |
|
|
|
42 |
logging.basicConfig(level=logging.INFO)
|
43 |
logger = logging.getLogger(__name__)
|
44 |
|
45 |
+
# ์ธ์
์ํ ์ด๊ธฐํ - ๊ฐ์ฅ ๋จผ์ ์คํ๋๋๋ก ์ต์๋จ์ ๋ฐฐ์น
|
46 |
if 'initialized' not in st.session_state:
|
47 |
st.session_state.initialized = True
|
48 |
st.session_state.wrong_questions = []
|
|
|
54 |
st.session_state.questions = []
|
55 |
logger.info("Session state initialized")
|
56 |
|
57 |
+
|
58 |
# ๋ฌธ์ ์์ฑ๊ธฐ ์ด๊ธฐํ
|
59 |
@st.cache_resource
|
60 |
def load_question_generator():
|
|
|
92 |
st.session_state.generated_questions = []
|
93 |
logger.info("Quiz started")
|
94 |
|
95 |
+
def generate_similar_question(wrong_q, misconception_id, generator):
|
96 |
+
"""์ ์ฌ ๋ฌธ์ ์์ฑ"""
|
97 |
+
logger.info(f"Generating similar question for misconception_id: {misconception_id}")
|
98 |
+
|
99 |
+
# ์
๋ ฅ ๋ฐ์ดํฐ ์ ํจ์ฑ ๊ฒ์ฌ
|
100 |
+
if not isinstance(wrong_q, dict):
|
101 |
+
logger.error(f"Invalid wrong_q type: {type(wrong_q)}")
|
102 |
+
st.error("์ ์ฌ ๋ฌธ์ ์์ฑ์ ํ์ํ ๋ฐ์ดํฐ ํ์์ด ์๋ชป๋์์ต๋๋ค.")
|
103 |
+
return None
|
104 |
+
|
105 |
+
try:
|
106 |
+
# misconception_id๊ฐ ์๊ฑฐ๋ NaN์ธ ๊ฒฝ์ฐ ๋ค๋ฅธ misconception ์ฌ์ฉ
|
107 |
+
if pd.isna(misconception_id):
|
108 |
+
logger.info("Original misconception_id is NaN, trying to find alternative")
|
109 |
+
# ํ์ฌ๊น์ง ๋์จ misconception๋ค ์ค์์ ์ ํ
|
110 |
+
available_misconceptions = [m for m in st.session_state.misconceptions if not pd.isna(m)]
|
111 |
+
|
112 |
+
if available_misconceptions:
|
113 |
+
# ๊ฐ์ฅ ์ต๊ทผ์ ๋์จ misconception ์ ํ
|
114 |
+
misconception_id = available_misconceptions[-1]
|
115 |
+
logger.info(f"Using alternative misconception_id: {misconception_id}")
|
116 |
+
else:
|
117 |
+
# ๊ธฐ๋ณธ misconception ID ์ฌ์ฉ (์: ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ misconception)
|
118 |
+
misconception_id = 2001 # ์ ์ ํ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์์ ํ์
|
119 |
+
logger.info(f"Using default misconception_id: {misconception_id}")
|
120 |
+
|
121 |
+
# ๋ฐ์ดํฐ ์ค๋น (ํํ ๋ณํ ๋ฐฉ์ง)
|
122 |
+
input_data = {
|
123 |
+
'construct_name': str(wrong_q.get('ConstructName', '')),
|
124 |
+
'subject_name': str(wrong_q.get('SubjectName', '')),
|
125 |
+
'question_text': str(wrong_q.get('QuestionText', '')),
|
126 |
+
'correct_answer_text': str(wrong_q.get(f'Answer{wrong_q["CorrectAnswer"]}Text', '')),
|
127 |
+
'wrong_answer_text': str(wrong_q.get(f'Answer{st.session_state.selected_wrong_answer}Text', '')),
|
128 |
+
'misconception_id': int(misconception_id)
|
129 |
+
}
|
130 |
+
|
131 |
+
logger.info(f"Prepared input data: {input_data}")
|
132 |
+
|
133 |
+
with st.spinner("๐ ์ ์ฌ ๋ฌธ์ ๋ฅผ ์์ฑํ๊ณ ์์ต๋๋ค..."):
|
134 |
+
# ์ ์ฌ ๋ฌธ์ ์์ฑ ํธ์ถ
|
135 |
+
generated_q, _ = generator.generate_similar_question_with_text(
|
136 |
+
construct_name=input_data['construct_name'],
|
137 |
+
subject_name=input_data['subject_name'],
|
138 |
+
question_text=input_data['question_text'],
|
139 |
+
correct_answer_text=input_data['correct_answer_text'],
|
140 |
+
wrong_answer_text=input_data['wrong_answer_text'],
|
141 |
+
misconception_id=input_data['misconception_id']
|
142 |
+
)
|
143 |
+
|
144 |
+
if generated_q:
|
145 |
+
verifier = load_answer_verifier()
|
146 |
+
with st.status("๐ค AI๊ฐ ๋ฌธ์ ๋ฅผ ๊ฒํ ํ๊ณ ์์ต๋๋ค..."):
|
147 |
+
st.write("๋ต์์ ์ ํ์ฑ์ ๊ฒ์ฆํ๊ณ ์์ต๋๋ค...")
|
148 |
+
verified_answer = verifier.verify_answer(
|
149 |
+
question=generated_q.question,
|
150 |
+
choices=generated_q.choices
|
151 |
+
)
|
152 |
+
|
153 |
+
if verified_answer:
|
154 |
+
logger.info(f"Answer verified: {verified_answer}")
|
155 |
+
st.write("โ
๊ฒ์ฆ ์๋ฃ!")
|
156 |
+
result = {
|
157 |
+
'question': generated_q.question,
|
158 |
+
'choices': generated_q.choices,
|
159 |
+
'correct': verified_answer,
|
160 |
+
'explanation': generated_q.explanation
|
161 |
+
}
|
162 |
+
st.session_state['current_similar_question_answer'] = verified_answer
|
163 |
+
return result
|
164 |
+
else:
|
165 |
+
logger.warning("Answer verification failed, using original answer")
|
166 |
+
st.write("โ ๏ธ ๊ฒ์ฆ์ ์คํจํ์ต๋๋ค. ์๋ณธ ๋ต์์ ์ฌ์ฉํฉ๋๋ค.")
|
167 |
+
result = {
|
168 |
+
'question': generated_q.question,
|
169 |
+
'choices': generated_q.choices,
|
170 |
+
'correct': generated_q.correct_answer,
|
171 |
+
'explanation': generated_q.explanation
|
172 |
+
}
|
173 |
+
st.session_state['current_similar_question_answer'] = generated_q.correct_answer
|
174 |
+
return result
|
175 |
+
|
176 |
+
except Exception as e:
|
177 |
+
logger.error(f"Error in generate_similar_question: {str(e)}")
|
178 |
+
st.error(f"๋ฌธ์ ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}")
|
179 |
+
return None
|
180 |
+
|
181 |
+
return None
|
182 |
+
|
183 |
def handle_answer(answer, current_q):
|
184 |
"""๋ต๋ณ ์ฒ๋ฆฌ"""
|
185 |
if answer != current_q['CorrectAnswer']:
|
186 |
wrong_q_dict = current_q.to_dict()
|
187 |
st.session_state.wrong_questions.append(wrong_q_dict)
|
188 |
st.session_state.selected_wrong_answer = answer
|
189 |
+
|
190 |
misconception_key = f'Misconception{answer}Id'
|
191 |
misconception_id = current_q.get(misconception_key)
|
192 |
st.session_state.misconceptions.append(misconception_id)
|
193 |
+
|
194 |
st.session_state.current_question_index += 1
|
195 |
+
if st.session_state.current_question_index >= len(st.session_state.questions):
|
196 |
st.session_state.current_step = 'review'
|
197 |
+
else:
|
198 |
+
st.session_state.current_step = 'quiz'
|
199 |
|
200 |
+
def display_math_content(content):
|
201 |
+
"""
|
202 |
+
Display mathematical content with proper formatting.
|
203 |
+
|
204 |
+
Args:
|
205 |
+
content (str): The math content to display
|
206 |
+
"""
|
207 |
+
# Convert LaTeX to plain text for display
|
208 |
+
from pylatexenc.latex2text import LatexNodes2Text
|
209 |
+
|
210 |
+
# Clean and format the content
|
211 |
+
formatted_content = LatexNodes2Text().latex_to_text(content)
|
212 |
+
st.markdown(f'<div class="math-container">{formatted_content}</div>', unsafe_allow_html=True)
|
213 |
+
|
214 |
+
def add_custom_css():
|
215 |
+
st.markdown(
|
216 |
+
"""
|
217 |
+
<style>
|
218 |
+
.problem-header {
|
219 |
+
color: #FF6B6B;
|
220 |
+
font-size: 24px;
|
221 |
+
font-weight: bold;
|
222 |
+
margin-bottom: 20px;
|
223 |
+
}
|
224 |
+
.math-container {
|
225 |
+
background-color: #f0f8ff;
|
226 |
+
padding: 15px 20px;
|
227 |
+
border-radius: 5px;
|
228 |
+
margin: 5px 0;
|
229 |
+
}
|
230 |
+
button {
|
231 |
+
color: #0066ff;
|
232 |
+
font-weight: 500;
|
233 |
+
}
|
234 |
+
</style>
|
235 |
+
""",
|
236 |
+
unsafe_allow_html=True
|
237 |
+
)
|
238 |
+
|
239 |
+
def display_question(question, answers):
|
240 |
+
"""Display question and options with LaTeX formatting"""
|
241 |
+
st.markdown('<div class="problem-header">Problem:</div>', unsafe_allow_html=True)
|
242 |
+
display_math_content(question)
|
243 |
+
|
244 |
+
# Add custom CSS for options
|
245 |
+
st.markdown("""
|
246 |
+
<style>
|
247 |
+
.option-container {
|
248 |
+
background-color: #f0f8ff;
|
249 |
+
padding: 10px 20px;
|
250 |
+
margin: 5px 0;
|
251 |
+
border-radius: 5px;
|
252 |
+
cursor: pointer;
|
253 |
+
display: flex;
|
254 |
+
align-items: center;
|
255 |
+
gap: 20px;
|
256 |
+
}
|
257 |
+
.option-text {
|
258 |
+
color: #0066ff;
|
259 |
+
font-weight: 500;
|
260 |
+
width: 30px;
|
261 |
+
}
|
262 |
+
</style>
|
263 |
+
""", unsafe_allow_html=True)
|
264 |
+
|
265 |
+
# Display options
|
266 |
+
for opt in ['A', 'B', 'C', 'D']:
|
267 |
+
with st.container():
|
268 |
+
col1, col2 = st.columns([1, 11])
|
269 |
+
with col1:
|
270 |
+
if st.button(f"{opt}.", key=f"btn_{opt}", help="Click to select"):
|
271 |
+
handle_answer(opt, st.session_state.questions.iloc[st.session_state.current_question_index])
|
272 |
+
st.rerun()
|
273 |
+
with col2:
|
274 |
+
display_option_content(answers[opt])
|
275 |
+
|
276 |
+
def display_option_content(option_text):
|
277 |
+
"""Process and display option content with LaTeX formatting"""
|
278 |
+
from pylatexenc.latex2text import LatexNodes2Text
|
279 |
+
formatted_content = LatexNodes2Text().latex_to_text(option_text)
|
280 |
+
st.markdown(f'<div class="math-container">{formatted_content}</div>', unsafe_allow_html=True)
|
281 |
+
|
282 |
+
def update_similar_question_display(new_question, i, answered=False):
|
283 |
+
"""Display similar question and its options"""
|
284 |
+
display_math_content(new_question['question'])
|
285 |
+
|
286 |
+
# Display options
|
287 |
+
for opt in ['A', 'B', 'C', 'D']:
|
288 |
+
with st.container():
|
289 |
+
col1, col2 = st.columns([1, 11])
|
290 |
+
with col1:
|
291 |
+
if st.button(f"{opt}.", key=f"sim_btn_{opt}_{i}", help="Click to select"):
|
292 |
+
if not answered:
|
293 |
+
# ์ ํํ ์ต์
(opt)์ st.session_state์ ์ ์ฅ
|
294 |
+
st.session_state[f"similar_question_answered_{i}"] = True
|
295 |
+
st.session_state[f"selected_answer_{i}"] = opt
|
296 |
+
correct_answer = st.session_state.get('current_similar_question_answer')
|
297 |
+
# ์ ๋ต ์ฌ๋ถ๋ฅผ ํ์ธ
|
298 |
+
st.session_state[f"is_correct_{i}"] = (opt == correct_answer)
|
299 |
+
st.rerun()
|
300 |
+
with col2:
|
301 |
+
display_option_content(new_question['choices'][opt])
|
302 |
|
|
|
|
|
|
|
|
|
303 |
|
304 |
def main():
|
305 |
"""๋ฉ์ธ ์ ํ๋ฆฌ์ผ์ด์
๋ก์ง"""
|
|
|
308 |
# Misconception Model ๋ก๋
|
309 |
misconception_model = load_misconception_model()
|
310 |
|
311 |
+
# Generator ์ด๊ธฐํ
|
312 |
+
generator = load_question_generator()
|
313 |
+
add_custom_css()
|
314 |
+
|
315 |
# ์ด๊ธฐ ํ๋ฉด
|
316 |
if st.session_state.current_step == 'initial':
|
317 |
st.write("#### ํ์ต์ ์์ํ๊ฒ ์ต๋๋ค. 10๊ฐ์ ๋ฌธ์ ๋ฅผ ํ์ด๋ณผ๊น์?")
|
|
|
322 |
# ํด์ฆ ํ๋ฉด
|
323 |
elif st.session_state.current_step == 'quiz':
|
324 |
current_q = st.session_state.questions.iloc[st.session_state.current_question_index]
|
325 |
+
|
326 |
# ์งํ ์ํฉ ํ์
|
327 |
progress = st.session_state.current_question_index / 10
|
328 |
st.progress(progress)
|
329 |
st.write(f"### ๋ฌธ์ {st.session_state.current_question_index + 1}/10")
|
330 |
+
|
331 |
# ๋ฌธ์ ํ์
|
332 |
st.markdown("---")
|
333 |
+
question_row = current_q['QuestionText']
|
334 |
+
question_text = LatexNodes2Text().latex_to_text(current_q['QuestionText'])
|
335 |
+
|
336 |
+
answers ={
|
337 |
+
'A': current_q['AnswerAText'],
|
338 |
+
'B': current_q['AnswerBText'],
|
339 |
+
'C': current_q['AnswerCText'],
|
340 |
+
'D': current_q['AnswerDText']
|
341 |
+
}
|
342 |
+
|
343 |
+
display_question(question_text, answers)
|
344 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
|
346 |
# ๋ณต์ต ํ๋ฉด
|
347 |
elif st.session_state.current_step == 'review':
|
348 |
st.write("### ํ์ต ๊ฒฐ๊ณผ")
|
349 |
+
|
350 |
# ๊ฒฐ๊ณผ ํต๊ณ
|
351 |
col1, col2, col3 = st.columns(3)
|
352 |
col1.metric("์ด ๋ฌธ์ ์", 10)
|
353 |
col2.metric("๋ง์ ๋ฌธ์ ", 10 - len(st.session_state.wrong_questions))
|
354 |
col3.metric("ํ๋ฆฐ ๋ฌธ์ ", len(st.session_state.wrong_questions))
|
355 |
+
|
356 |
+
# ๊ฒฐ๊ณผ์ ๋ฐ๋ฅธ ๋ฉ์์ง ํ์
|
357 |
+
if len(st.session_state.wrong_questions) == 0:
|
358 |
+
st.balloons() # ์ถํ ํจ๊ณผ
|
359 |
+
st.success("๐ ์ถํํฉ๋๋ค! ๋ชจ๋ ๋ฌธ์ ๋ฅผ ๋ง์ถ์
จ์ด์!")
|
360 |
+
st.markdown("""
|
361 |
+
### ๐ ์ํ์์ด์ญ๋๋ค!
|
362 |
+
์๋ฒฝํ ์ ์๋ฅผ ๋ฐ์ผ์
จ๋ค์! ์ํ์ ๊ฐ๋
์ ์ ํํ๊ฒ ์ดํดํ๊ณ ๊ณ์ ๊ฒ ๊ฐ์ต๋๋ค.
|
363 |
+
""")
|
364 |
+
elif len(st.session_state.wrong_questions) <= 3:
|
365 |
+
st.success("์ ํ์
จ์ด์! ์กฐ๊ธ๋ง ๋ ์ฐ์ตํ๋ฉด ์๋ฒฝํ ๊ฑฐ์์!")
|
366 |
+
else:
|
367 |
+
st.info("์ฒ์ฒํ ๊ฐ๋
์ ๋ณต์ตํด๋ณด์์. ์ฐ์ตํ๋ค ๋ณด๋ฉด ๋์ด๋ ๊ฑฐ์์!")
|
368 |
+
|
369 |
+
# ๋ค๋น๊ฒ์ด์
๋ฒํผ
|
370 |
+
col1, col2 = st.columns(2)
|
371 |
+
with col1:
|
372 |
+
if st.button("๐ ์๋ก์ด ๋ฌธ์ ์ธํธ ์์ํ๊ธฐ", use_container_width=True):
|
373 |
+
start_quiz()
|
374 |
+
st.rerun()
|
375 |
+
with col2:
|
376 |
+
if st.button("๐ ์ฒ์์ผ๋ก ๋์๊ฐ๊ธฐ", use_container_width=True):
|
377 |
+
st.session_state.clear()
|
378 |
+
st.rerun()
|
379 |
+
|
380 |
+
# ํ๋ฆฐ ๋ฌธ์ ๋ถ์ ๋ถ๋ถ
|
381 |
if st.session_state.wrong_questions:
|
382 |
st.write("### โ๏ธ ํ๋ฆฐ ๋ฌธ์ ๋ถ์")
|
383 |
tabs = st.tabs([f"๐ ํ๋ฆฐ ๋ฌธ์ #{i + 1}" for i in range(len(st.session_state.wrong_questions))])
|
384 |
+
|
385 |
for i, (tab, (wrong_q, misconception_id)) in enumerate(zip(
|
386 |
tabs,
|
387 |
zip(st.session_state.wrong_questions, st.session_state.misconceptions)
|
388 |
)):
|
389 |
with tab:
|
390 |
st.write("**๐ ๋ฌธ์ :**")
|
391 |
+
display_math_content(wrong_q['QuestionText']) # ๋ฌธ์ ๋ ๋๋ง
|
392 |
+
st.write("**โ
์ ๋ต:**")
|
393 |
+
display_option_content(wrong_q[f'Answer{wrong_q["CorrectAnswer"]}Text'])
|
394 |
|
395 |
st.write("---")
|
396 |
st.write("**๐ ๊ด๋ จ๋ Misconception:**")
|
397 |
if misconception_id and not pd.isna(misconception_id):
|
398 |
+
misconception_text = generator.get_misconception_text(misconception_id)
|
399 |
st.info(f"Misconception ID: {int(misconception_id)}\n\n{misconception_text}")
|
400 |
else:
|
401 |
st.info("Misconception ์ ๋ณด๊ฐ ์์ต๋๋ค.")
|
402 |
+
|
403 |
+
if st.button(f"๐ ์ ์ฌ ๋ฌธ์ ํ๊ธฐ", key=f"retry_{i}"):
|
404 |
+
st.session_state[f"show_similar_question_{i}"] = True
|
405 |
+
st.session_state[f"similar_question_answered_{i}"] = False
|
406 |
+
st.rerun()
|
407 |
+
if st.session_state.get(f"show_similar_question_{i}", False):
|
408 |
+
st.divider()
|
409 |
+
new_question = generate_similar_question(wrong_q, misconception_id, generator)
|
410 |
+
if new_question:
|
411 |
+
st.write("### ๐ฏ ์ ์ฌ ๋ฌธ์ ")
|
412 |
+
#display_math_content(new_question['question']) # ํจ์ ๊ต์ฒด
|
413 |
+
|
414 |
+
# ๋ต๋ณ ์ํ ํ์ธ
|
415 |
+
answered = st.session_state.get(f"similar_question_answered_{i}", False)
|
416 |
+
#update_similar_question_display(new_question, i, answered)
|
417 |
+
# ์ ํํ ์ต์
์ ์ฒ๋ฆฌํ๋ ํจ์๋ฅผ ํธ์ถ
|
418 |
+
update_similar_question_display(new_question, i)
|
419 |
+
|
420 |
+
# ๋ต๋ณํ ๊ฒฝ์ฐ ๊ฒฐ๊ณผ ํ์
|
421 |
+
if answered:
|
422 |
+
is_correct = st.session_state.get(f"is_correct_{i}", False)
|
423 |
+
correct_answer = st.session_state.get('current_similar_question_answer')
|
424 |
+
if is_correct:
|
425 |
+
st.success("โ
์ ๋ต์
๋๋ค!")
|
426 |
+
else:
|
427 |
+
st.error(f"โ ํ๋ ธ์ต๋๋ค. ์ ๋ต์ {correct_answer}์
๋๋ค.")
|
428 |
+
|
429 |
+
# ํด์ค ํ์
|
430 |
+
st.write("---")
|
431 |
+
st.write("**๐ ํด์ค:**", new_question['explanation'])
|
432 |
+
|
433 |
+
# ๋ค์ ํ๊ธฐ ๋ฒํผ
|
434 |
+
if st.button("๐ ๋ค์ ํ๊ธฐ", key=f"reset_{i}"):
|
435 |
+
st.session_state[f"similar_question_answered_{i}"] = False
|
436 |
+
st.session_state[f"selected_answer_{i}"] = None
|
437 |
+
st.session_state[f"is_correct_{i}"] = None
|
438 |
+
st.rerun()
|
439 |
+
|
440 |
+
# ๋ฌธ์ ๋ซ๊ธฐ ๋ฒํผ
|
441 |
+
if st.button("โ ๋ฌธ์ ๋ซ๊ธฐ", key=f"close_{i}"):
|
442 |
+
st.session_state[f"show_similar_question_{i}"] = False
|
443 |
+
st.session_state[f"similar_question_answered_{i}"] = False
|
444 |
+
st.session_state[f"selected_answer_{i}"] = None
|
445 |
+
st.session_state[f"is_correct_{i}"] = None
|
446 |
+
st.rerun()
|
447 |
+
|
448 |
+
# ํ๋ฉด ์๋ ์ฌ๋ฐฑ ์ถ๊ฐ
|
449 |
+
st.markdown("<br>" * 5, unsafe_allow_html=True) # 5์ค์ ๋น ์ค ์ถ๊ฐ
|
450 |
+
st.markdown("""
|
451 |
+
<div style="height: 100px;">
|
452 |
+
</div>
|
453 |
+
""", unsafe_allow_html=True) # ์ถ๊ฐ ์ฌ๋ฐฑ
|
454 |
+
else:
|
455 |
+
st.error("์ ์ฌ ๋ฌธ์ ๋ฅผ ์์ฑํ ์ ์์ต๋๋ค.")
|
456 |
+
if st.button("โ ๋ซ๊ธฐ", key=f"close_error_{i}"):
|
457 |
+
st.session_state[f"show_similar_question_{i}"] = False
|
458 |
+
st.rerun()
|
459 |
+
# ํ๋ฉด ์๋ ์ฌ๋ฐฑ ์ถ๊ฐ
|
460 |
+
st.markdown("<br>" * 5, unsafe_allow_html=True) # 5์ค์ ๋น ์ค ์ถ๊ฐ
|
461 |
+
st.markdown("""
|
462 |
+
<div style="height: 100px;">
|
463 |
+
</div>
|
464 |
+
""", unsafe_allow_html=True) # ์ถ๊ฐ ์ฌ๋ฐฑ
|
465 |
+
|
466 |
+
|
467 |
+
# # ํ๋ฆฐ ๋ฌธ์ ๋ถ์
|
468 |
+
# if st.session_state.wrong_questions:
|
469 |
+
# st.write("### โ๏ธ ํ๋ฆฐ ๋ฌธ์ ๋ถ์")
|
470 |
+
# tabs = st.tabs([f"๐ ํ๋ฆฐ ๋ฌธ์ #{i + 1}" for i in range(len(st.session_state.wrong_questions))])
|
471 |
+
|
472 |
+
# for i, (tab, (wrong_q, misconception_id)) in enumerate(zip(
|
473 |
+
# tabs,
|
474 |
+
# zip(st.session_state.wrong_questions, st.session_state.misconceptions)
|
475 |
+
# )):
|
476 |
+
# with tab:
|
477 |
+
# st.write("**๐ ๋ฌธ์ :**")
|
478 |
+
# st.write(wrong_q['QuestionText'])
|
479 |
+
# st.write("**โ
์ ๋ต:**", wrong_q['CorrectAnswer'])
|
480 |
+
|
481 |
+
# st.write("---")
|
482 |
+
# st.write("**๐ ๊ด๋ จ๋ Misconception:**")
|
483 |
+
# if misconception_id and not pd.isna(misconception_id):
|
484 |
+
# misconception_text = misconception_model.misconception_names.get(misconception_id, "์ ๋ณด ์์")
|
485 |
+
# st.info(f"Misconception ID: {int(misconception_id)}\n\n{misconception_text}")
|
486 |
+
# else:
|
487 |
+
# st.info("Misconception ์ ๋ณด๊ฐ ์์ต๋๋ค.")
|
488 |
|
489 |
if __name__ == "__main__":
|
490 |
main()
|
491 |
+
|
492 |
+
|
493 |
+
# random_state 42์์ ์ ๋ต
|
494 |
+
# D C A A C
|
495 |
+
# A B B B B
|