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
  # ๋ณต์Šต ํ™”๋ฉด