Jintonic92 commited on
Commit
cd93920
Β·
verified Β·
1 Parent(s): 8181918

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -44
app.py CHANGED
@@ -183,6 +183,32 @@ 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 format_latex_expression(text: str) -> str:
187
  """μˆ˜ν•™ ν‘œν˜„μ‹μ„ LaTeX ν˜•μ‹μœΌλ‘œ λ³€ν™˜"""
188
  import re
@@ -190,10 +216,6 @@ def format_latex_expression(text: str) -> str:
190
  # μ΄νƒ€λ¦­μ²΄λ‘œ ν‘œμ‹œν•  μˆ˜ν•™ μš©μ–΄λ“€
191
  math_terms = ['decimalplaces', 'rounded to', 'What is']
192
 
193
- def replace_math_terms(match):
194
- term = match.group(0)
195
- return f'\\text{{{term}}}'
196
-
197
  # ν…μŠ€νŠΈ μ „μ²˜λ¦¬
198
  text = text.replace('\\(', '\\left(')
199
  text = text.replace('\\)', '\\right)')
@@ -208,10 +230,10 @@ def format_latex_expression(text: str) -> str:
208
 
209
  # 특수 νŒ¨ν„΄ 처리
210
  replacements = {
211
- r'\\div': '\\div',
212
- r'\\ldots': '\\ldots',
213
- r'\\dots': '\\dots',
214
- r'\\times': '\\times',
215
  }
216
 
217
  for old, new in replacements.items():
@@ -229,37 +251,6 @@ def format_latex_expression(text: str) -> str:
229
  text = f'$${text}$$'
230
 
231
  return text
232
-
233
- def format_question(question: str) -> str:
234
- """문제 ν…μŠ€νŠΈλ₯Ό LaTeX ν˜•μ‹μœΌλ‘œ λ³€ν™˜"""
235
- # 색상이 μžˆλŠ” ν…μŠ€νŠΈ 처리
236
- colored_text_pattern = r'\\textcolor{([^}]+)}{([^}]+)}'
237
-
238
- def process_colored_text(match):
239
- color = match.group(1)
240
- text = match.group(2)
241
- return f'\\textcolor{{{color}}}{{{format_latex_expression(text)}}}'
242
-
243
- question = re.sub(colored_text_pattern, process_colored_text, question)
244
- return format_latex_expression(question)
245
-
246
- def format_answer_choice(choice: str) -> str:
247
- """선택지 ν…μŠ€νŠΈλ₯Ό LaTeX ν˜•μ‹μœΌλ‘œ λ³€ν™˜"""
248
- # λ‹¬λŸ¬ κΈ°ν˜Έκ°€ ν¬ν•¨λœ 선택지 νŠΉλ³„ 처리
249
- if '$' in choice:
250
- # λ‹¬λŸ¬ 기호λ₯Ό LaTeX λͺ…λ Ήμ–΄λ‘œ λ³€ν™˜
251
- choice = choice.replace('$', '\\$')
252
- return format_latex_expression(choice)
253
-
254
- def display_math_content(content: str, is_question: bool = True):
255
- """μˆ˜ν•™ λ‚΄μš©(문제 λ˜λŠ” λ‹΅μ•ˆ) ν‘œμ‹œ"""
256
- formatted_content = format_math_expression(content)
257
-
258
- if is_question:
259
- st.markdown(formatted_content)
260
- else:
261
- # μ„ νƒμ§€μ˜ 경우 μΆ”κ°€ ν¬λ§·νŒ… ν•„μš”ν•  수 있음
262
- return formatted_content
263
 
264
  def main():
265
  """메인 μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 둜직"""
@@ -286,7 +277,9 @@ def main():
286
 
287
  # 문제 ν‘œμ‹œ
288
  st.markdown("---")
289
- display_math_question(current_q['QuestionText'])
 
 
290
  #st.write(current_q['QuestionText'])
291
 
292
  # # 보기 ν‘œμ‹œ
@@ -309,17 +302,17 @@ def main():
309
  # 보기 ν‘œμ‹œ
310
  col1, col2 = st.columns(2)
311
  with col1:
312
- if st.button(f"A) {format_math_expression(current_q['AnswerAText'])}", key="A"):
313
  handle_answer('A', current_q)
314
  st.rerun()
315
- if st.button(f"C) {format_math_expression(current_q['AnswerCText'])}", key="C"):
316
  handle_answer('C', current_q)
317
  st.rerun()
318
  with col2:
319
- if st.button(f"B) {format_math_expression(current_q['AnswerBText'])}", key="B"):
320
  handle_answer('B', current_q)
321
  st.rerun()
322
- if st.button(f"D) {format_math_expression(current_q['AnswerDText'])}", key="D"):
323
  handle_answer('D', current_q)
324
  st.rerun()
325
  # 볡슡 ν™”λ©΄
 
183
  if st.session_state.current_question_index >= 10:
184
  st.session_state.current_step = 'review'
185
 
186
+ def format_question(question: str) -> str:
187
+ """문제 ν…μŠ€νŠΈλ₯Ό LaTeX ν˜•μ‹μœΌλ‘œ λ³€ν™˜"""
188
+ # 색상이 μžˆλŠ” ν…μŠ€νŠΈ 처리
189
+ colored_text_pattern = r'\\textcolor{([^}]+)}{([^}]+)}'
190
+
191
+ def process_colored_text(match):
192
+ color = match.group(1)
193
+ text = match.group(2)
194
+ return f'\\textcolor{{{color}}}{{{format_latex_expression(text)}}}'
195
+
196
+ question = re.sub(colored_text_pattern, process_colored_text, question)
197
+ return format_latex_expression(question)
198
+
199
+ def format_answer_choice(choice: str) -> str:
200
+ """선택지 ν…μŠ€νŠΈλ₯Ό LaTeX ν˜•μ‹μœΌλ‘œ λ³€ν™˜"""
201
+ # λ‹¬λŸ¬ κΈ°ν˜Έκ°€ ν¬ν•¨λœ 선택지 νŠΉλ³„ 처리
202
+ if '$' in choice:
203
+ # λ‹¬λŸ¬ 기호λ₯Ό LaTeX λͺ…λ Ήμ–΄λ‘œ λ³€ν™˜
204
+ choice = choice.replace('$', '\\$')
205
+ return format_latex_expression(choice)
206
+
207
+ def display_math_content(content: str, is_question: bool = True):
208
+ """μˆ˜ν•™ λ‚΄μš©μ„ 화면에 ν‘œμ‹œ"""
209
+ formatted_content = format_latex_expression(content)
210
+ st.markdown(formatted_content, unsafe_allow_html=True)
211
+
212
  def format_latex_expression(text: str) -> str:
213
  """μˆ˜ν•™ ν‘œν˜„μ‹μ„ LaTeX ν˜•μ‹μœΌλ‘œ λ³€ν™˜"""
214
  import re
 
216
  # μ΄νƒ€λ¦­μ²΄λ‘œ ν‘œμ‹œν•  μˆ˜ν•™ μš©μ–΄λ“€
217
  math_terms = ['decimalplaces', 'rounded to', 'What is']
218
 
 
 
 
 
219
  # ν…μŠ€νŠΈ μ „μ²˜λ¦¬
220
  text = text.replace('\\(', '\\left(')
221
  text = text.replace('\\)', '\\right)')
 
230
 
231
  # 특수 νŒ¨ν„΄ 처리
232
  replacements = {
233
+ r'\div': '\\div',
234
+ r'\ldots': '\\ldots',
235
+ r'\dots': '\\dots',
236
+ r'\times': '\\times',
237
  }
238
 
239
  for old, new in replacements.items():
 
251
  text = f'$${text}$$'
252
 
253
  return text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
 
255
  def main():
256
  """메인 μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 둜직"""
 
277
 
278
  # 문제 ν‘œμ‹œ
279
  st.markdown("---")
280
+ #display_math_question(current_q['QuestionText'])
281
+ display_math_content(current_q['QuestionText']) # display_math_question λŒ€μ‹  display_math_content μ‚¬μš©
282
+
283
  #st.write(current_q['QuestionText'])
284
 
285
  # # 보기 ν‘œμ‹œ
 
302
  # 보기 ν‘œμ‹œ
303
  col1, col2 = st.columns(2)
304
  with col1:
305
+ if st.button(format_latex_expression(f"A) {current_q['AnswerAText']}"), key="A"):
306
  handle_answer('A', current_q)
307
  st.rerun()
308
+ if st.button(format_latex_expression(f"C) {current_q['AnswerCText']}"), key="C"):
309
  handle_answer('C', current_q)
310
  st.rerun()
311
  with col2:
312
+ if st.button(format_latex_expression(f"B) {current_q['AnswerBText']}"), key="B"):
313
  handle_answer('B', current_q)
314
  st.rerun()
315
+ if st.button(format_latex_expression(f"D) {current_q['AnswerDText']}"), key="D"):
316
  handle_answer('D', current_q)
317
  st.rerun()
318
  # 볡슡 ν™”λ©΄