Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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'
|
212 |
-
r'
|
213 |
-
r'
|
214 |
-
r'
|
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) {
|
313 |
handle_answer('A', current_q)
|
314 |
st.rerun()
|
315 |
-
if st.button(f"C) {
|
316 |
handle_answer('C', current_q)
|
317 |
st.rerun()
|
318 |
with col2:
|
319 |
-
if st.button(f"B) {
|
320 |
handle_answer('B', current_q)
|
321 |
st.rerun()
|
322 |
-
if st.button(f"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 |
# λ³΅μ΅ νλ©΄
|