Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -183,6 +183,50 @@ def handle_answer(answer, current_q):
|
|
| 183 |
if st.session_state.current_question_index >= 10:
|
| 184 |
st.session_state.current_step = 'review'
|
| 185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
def main():
|
| 187 |
"""๋ฉ์ธ ์ ํ๋ฆฌ์ผ์ด์
๋ก์ง"""
|
| 188 |
st.title("MisconcepTutor")
|
|
@@ -208,25 +252,42 @@ def main():
|
|
| 208 |
|
| 209 |
# ๋ฌธ์ ํ์
|
| 210 |
st.markdown("---")
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
# ๋ณด๊ธฐ ํ์
|
| 214 |
col1, col2 = st.columns(2)
|
| 215 |
with col1:
|
| 216 |
-
if st.button(f"A) {current_q['AnswerAText']}", key="A"):
|
| 217 |
handle_answer('A', current_q)
|
| 218 |
st.rerun()
|
| 219 |
-
if st.button(f"C) {current_q['AnswerCText']}", key="C"):
|
| 220 |
handle_answer('C', current_q)
|
| 221 |
st.rerun()
|
| 222 |
with col2:
|
| 223 |
-
if st.button(f"B) {current_q['AnswerBText']}", key="B"):
|
| 224 |
handle_answer('B', current_q)
|
| 225 |
st.rerun()
|
| 226 |
-
if st.button(f"D) {current_q['AnswerDText']}", key="D"):
|
| 227 |
handle_answer('D', current_q)
|
| 228 |
st.rerun()
|
| 229 |
-
|
| 230 |
# ๋ณต์ต ํ๋ฉด
|
| 231 |
elif st.session_state.current_step == 'review':
|
| 232 |
st.write("### ํ์ต ๊ฒฐ๊ณผ")
|
|
|
|
| 183 |
if st.session_state.current_question_index >= 10:
|
| 184 |
st.session_state.current_step = 'review'
|
| 185 |
|
| 186 |
+
# ์์ ํํ
|
| 187 |
+
def format_math_expression(text: str) -> str:
|
| 188 |
+
"""์ํ ํํ์์ LaTeX ํ์์ผ๋ก ๋ณํ"""
|
| 189 |
+
import re
|
| 190 |
+
|
| 191 |
+
# ๊ธฐ๋ณธ์ ์ธ ์ํ ์ฐ์ฐ์ ๋ณํ
|
| 192 |
+
replacements = {
|
| 193 |
+
r'\รท': r'\div',
|
| 194 |
+
r'\ร': r'\times',
|
| 195 |
+
r'\-': r'-',
|
| 196 |
+
r'\+': r'+',
|
| 197 |
+
r'=': r'=',
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
# ๋ถ์ ํจํด ์ฐพ๊ธฐ (์: "1/2" โ "\frac{1}{2}")
|
| 201 |
+
text = re.sub(r'(\d+)/(\d+)', r'\\frac{\1}{\2}', text)
|
| 202 |
+
|
| 203 |
+
# ๊ดํธ ์ฒ๋ฆฌ
|
| 204 |
+
text = re.sub(r'\(([^)]+)\)', r'\(\1\)', text)
|
| 205 |
+
|
| 206 |
+
# ๋๋จธ์ง ์ํ ์ฐ์ฐ์ ๋ณํ
|
| 207 |
+
for old, new in replacements.items():
|
| 208 |
+
text = text.replace(old, new)
|
| 209 |
+
|
| 210 |
+
# ์์ ๋ถ๋ถ ์ฐพ์์ LaTeX๋ก ๊ฐ์ธ๊ธฐ
|
| 211 |
+
def wrap_math(match):
|
| 212 |
+
expr = match.group(1)
|
| 213 |
+
return f'${expr}$'
|
| 214 |
+
|
| 215 |
+
# ์์ ํจํด ์ฐพ์์ LaTeX๋ก ๋ณํ
|
| 216 |
+
text = re.sub(r'\(([^)]+)\)', wrap_math, text)
|
| 217 |
+
|
| 218 |
+
return text
|
| 219 |
+
|
| 220 |
+
def display_math_question(question: str):
|
| 221 |
+
"""์ํ ๋ฌธ์ ๋ฅผ LaTeX ํ์์ผ๋ก ํ์"""
|
| 222 |
+
formatted_question = format_math_expression(question)
|
| 223 |
+
st.markdown(formatted_question)
|
| 224 |
+
|
| 225 |
+
def display_math_answer(answer: str):
|
| 226 |
+
"""์ํ ๋ต์์ LaTeX ํ์์ผ๋ก ํ์"""
|
| 227 |
+
formatted_answer = format_math_expression(answer)
|
| 228 |
+
# ๊ดํธ ์์ ์์๋ง LaTeX๋ก ์ฒ๋ฆฌ
|
| 229 |
+
st.markdown(formatted_answer)
|
| 230 |
def main():
|
| 231 |
"""๋ฉ์ธ ์ ํ๋ฆฌ์ผ์ด์
๋ก์ง"""
|
| 232 |
st.title("MisconcepTutor")
|
|
|
|
| 252 |
|
| 253 |
# ๋ฌธ์ ํ์
|
| 254 |
st.markdown("---")
|
| 255 |
+
display_math_question(current_q['QuestionText'])
|
| 256 |
+
#st.write(current_q['QuestionText'])
|
| 257 |
+
|
| 258 |
+
# # ๋ณด๊ธฐ ํ์
|
| 259 |
+
# col1, col2 = st.columns(2)
|
| 260 |
+
# with col1:
|
| 261 |
+
# if st.button(f"A) {current_q['AnswerAText']}", key="A"):
|
| 262 |
+
# handle_answer('A', current_q)
|
| 263 |
+
# st.rerun()
|
| 264 |
+
# if st.button(f"C) {current_q['AnswerCText']}", key="C"):
|
| 265 |
+
# handle_answer('C', current_q)
|
| 266 |
+
# st.rerun()
|
| 267 |
+
# with col2:
|
| 268 |
+
# if st.button(f"B) {current_q['AnswerBText']}", key="B"):
|
| 269 |
+
# handle_answer('B', current_q)
|
| 270 |
+
# st.rerun()
|
| 271 |
+
# if st.button(f"D) {current_q['AnswerDText']}", key="D"):
|
| 272 |
+
# handle_answer('D', current_q)
|
| 273 |
+
# st.rerun()
|
| 274 |
|
| 275 |
# ๋ณด๊ธฐ ํ์
|
| 276 |
col1, col2 = st.columns(2)
|
| 277 |
with col1:
|
| 278 |
+
if st.button(f"A) {format_math_expression(current_q['AnswerAText'])}", key="A"):
|
| 279 |
handle_answer('A', current_q)
|
| 280 |
st.rerun()
|
| 281 |
+
if st.button(f"C) {format_math_expression(current_q['AnswerCText'])}", key="C"):
|
| 282 |
handle_answer('C', current_q)
|
| 283 |
st.rerun()
|
| 284 |
with col2:
|
| 285 |
+
if st.button(f"B) {format_math_expression(current_q['AnswerBText'])}", key="B"):
|
| 286 |
handle_answer('B', current_q)
|
| 287 |
st.rerun()
|
| 288 |
+
if st.button(f"D) {format_math_expression(current_q['AnswerDText'])}", key="D"):
|
| 289 |
handle_answer('D', current_q)
|
| 290 |
st.rerun()
|
|
|
|
| 291 |
# ๋ณต์ต ํ๋ฉด
|
| 292 |
elif st.session_state.current_step == 'review':
|
| 293 |
st.write("### ํ์ต ๊ฒฐ๊ณผ")
|