Jintonic92 commited on
Commit
2003b2c
ยท
verified ยท
1 Parent(s): aad959d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -6
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
- st.write(current_q['QuestionText'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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("### ํ•™์Šต ๊ฒฐ๊ณผ")