Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -206,57 +206,60 @@ def clean_text(text: str) -> str:
|
|
206 |
|
207 |
return text
|
208 |
|
209 |
-
def
|
210 |
-
"""
|
211 |
import re
|
212 |
|
213 |
-
#
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
# κΈ°λ³Έ μν κΈ°νΈ λ³ν
|
221 |
-
replacements = {
|
222 |
-
'Γ·': '\\div',
|
223 |
-
'Γ': '\\times',
|
224 |
-
'*': '\\cdot',
|
225 |
-
'β ': '\\neq',
|
226 |
-
'β€': '\\leq',
|
227 |
-
'β₯': '\\geq',
|
228 |
-
'β': '\\rightarrow',
|
229 |
-
'β': '\\leftarrow',
|
230 |
-
'Β±': '\\pm',
|
231 |
-
'β': '\\infty',
|
232 |
-
'β': '\\sqrt',
|
233 |
}
|
234 |
|
235 |
-
|
236 |
-
text = re.sub(r'(\d+)/(\d+)', r'\\frac{\1}{\2}', text)
|
237 |
-
|
238 |
-
# μν κΈ°νΈ λ³ν
|
239 |
-
for old, new in replacements.items():
|
240 |
text = text.replace(old, new)
|
241 |
|
242 |
-
#
|
243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
|
245 |
return text
|
246 |
|
247 |
-
def
|
248 |
-
"""μν
|
249 |
-
|
250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
|
252 |
-
def
|
253 |
-
"""
|
254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
|
256 |
def display_math_question(question: str):
|
257 |
"""μν λ¬Έμ λ₯Ό LaTeX νμμΌλ‘ νμ"""
|
258 |
formatted_question = format_math_expression(question)
|
259 |
-
st.markdown(formatted_question
|
260 |
|
261 |
def format_math_choices(choices: dict) -> dict:
|
262 |
"""μ νμ§μ μν ννμμ LaTeX νμμΌλ‘ λ³ν"""
|
|
|
206 |
|
207 |
return text
|
208 |
|
209 |
+
def clean_text(text: str) -> str:
|
210 |
+
"""ν
μ€νΈ μ μ²λ¦¬: λΆνμν λ¬Έμ μ κ±° λ° LaTeX νμμΌλ‘ λ³ν"""
|
211 |
import re
|
212 |
|
213 |
+
# LaTeX λͺ
λ Ήμ΄λ₯Ό μν μ΄μ€μΌμ΄ν μ²λ¦¬
|
214 |
+
latex_commands = {
|
215 |
+
r'\div': r'\\div',
|
216 |
+
r'\ldots': r'\\ldots',
|
217 |
+
r'\dots': r'\\ldots',
|
218 |
+
r'\cdot': r'\\cdot',
|
219 |
+
r'\times': r'\\times'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
}
|
221 |
|
222 |
+
for old, new in latex_commands.items():
|
|
|
|
|
|
|
|
|
223 |
text = text.replace(old, new)
|
224 |
|
225 |
+
# κ΄νΈ μμ μμμ LaTeXλ‘ λ³ν
|
226 |
+
def convert_to_latex(match):
|
227 |
+
content = match.group(1)
|
228 |
+
# μ΄λ―Έ $λ‘ λλ¬μΈμ¬ μλμ§ νμΈ
|
229 |
+
if not content.strip().startswith('$') and not content.strip().endswith('$'):
|
230 |
+
return f'$({content})$'
|
231 |
+
return f'({content})'
|
232 |
+
|
233 |
+
# κ΄νΈ μμ λ΄μ©μ LaTeXλ‘ λ³ν
|
234 |
+
text = re.sub(r'\((.*?)\)', convert_to_latex, text)
|
235 |
|
236 |
return text
|
237 |
|
238 |
+
def format_math_expression(text: str) -> str:
|
239 |
+
"""μν ννμμ LaTeX νμμΌλ‘ λ³ν"""
|
240 |
+
# κΈ°λ³Έ ν΄λ¦¬λ
|
241 |
+
text = clean_text(text)
|
242 |
+
|
243 |
+
# LaTeX μμ κΈ°νΈ μΆκ°
|
244 |
+
if not text.startswith('$') and not text.endswith('$'):
|
245 |
+
text = f'${text}$'
|
246 |
+
|
247 |
+
return text
|
248 |
|
249 |
+
def display_math_content(content: str, is_question: bool = True):
|
250 |
+
"""μν λ΄μ©(λ¬Έμ λλ λ΅μ) νμ"""
|
251 |
+
formatted_content = format_math_expression(content)
|
252 |
+
|
253 |
+
if is_question:
|
254 |
+
st.markdown(formatted_content)
|
255 |
+
else:
|
256 |
+
# μ νμ§μ κ²½μ° μΆκ° ν¬λ§·ν
νμν μ μμ
|
257 |
+
return formatted_content
|
258 |
|
259 |
def display_math_question(question: str):
|
260 |
"""μν λ¬Έμ λ₯Ό LaTeX νμμΌλ‘ νμ"""
|
261 |
formatted_question = format_math_expression(question)
|
262 |
+
st.markdown(formatted_question)
|
263 |
|
264 |
def format_math_choices(choices: dict) -> dict:
|
265 |
"""μ νμ§μ μν ννμμ LaTeX νμμΌλ‘ λ³ν"""
|