Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -204,51 +204,45 @@ def format_answer_choice(choice: str) -> str:
|
|
| 204 |
choice = choice.replace('$', '\\$')
|
| 205 |
return format_latex_expression(choice)
|
| 206 |
|
| 207 |
-
def display_math_content(
|
| 208 |
"""μν λ΄μ©μ νλ©΄μ νμ"""
|
| 209 |
-
|
| 210 |
-
st.markdown(
|
| 211 |
|
| 212 |
def format_latex_expression(text: str) -> str:
|
| 213 |
"""μν ννμμ LaTeX νμμΌλ‘ λ³ν"""
|
| 214 |
import re
|
| 215 |
-
|
| 216 |
-
# μ΄ν€λ¦μ²΄λ‘ νμν μν μ©μ΄λ€
|
| 217 |
-
math_terms = ['decimalplaces', 'rounded to', 'What is']
|
| 218 |
-
|
| 219 |
-
# ν
μ€νΈ μ μ²λ¦¬
|
| 220 |
-
text = text.replace('\\(', '\\left(')
|
| 221 |
-
text = text.replace('\\)', '\\right)')
|
| 222 |
-
|
| 223 |
-
# μν μ©μ΄λ₯Ό LaTeX ν
μ€νΈλ‘ λ³ν
|
| 224 |
-
for term in math_terms:
|
| 225 |
-
text = text.replace(term, f'\\text{{{term}}}')
|
| 226 |
-
|
| 227 |
-
# λ¬λ¬ κΈ°νΈ($) μ²λ¦¬
|
| 228 |
-
text = text.replace('$(', '\\$\\left(')
|
| 229 |
-
text = text.replace(')$', '\\right)\\$')
|
| 230 |
|
| 231 |
-
#
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
}
|
| 238 |
|
| 239 |
-
|
| 240 |
-
|
|
|
|
|
|
|
| 241 |
|
| 242 |
-
#
|
| 243 |
def process_math(match):
|
| 244 |
content = match.group(1)
|
| 245 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
-
|
|
|
|
| 248 |
|
| 249 |
-
#
|
| 250 |
-
|
| 251 |
-
text = f
|
| 252 |
|
| 253 |
return text
|
| 254 |
|
|
|
|
| 204 |
choice = choice.replace('$', '\\$')
|
| 205 |
return format_latex_expression(choice)
|
| 206 |
|
| 207 |
+
def display_math_content(text: str):
|
| 208 |
"""μν λ΄μ©μ νλ©΄μ νμ"""
|
| 209 |
+
formatted_text = format_latex_expression(text)
|
| 210 |
+
st.markdown(formatted_text, unsafe_allow_html=True)
|
| 211 |
|
| 212 |
def format_latex_expression(text: str) -> str:
|
| 213 |
"""μν ννμμ LaTeX νμμΌλ‘ λ³ν"""
|
| 214 |
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
+
# κΈ°μ‘΄ LaTeX μμ 보쑴
|
| 217 |
+
latex_parts = []
|
| 218 |
+
def save_latex(match):
|
| 219 |
+
latex_parts.append(match.group(0))
|
| 220 |
+
return f"LATEX_{len(latex_parts)-1}_PLACEHOLDER"
|
| 221 |
+
text = re.sub(r'\$\$.*?\$\$', save_latex, text)
|
|
|
|
| 222 |
|
| 223 |
+
# λ¨μ΄ λΆλ¦¬ (μ: "Tocalculate" -> "To calculate")
|
| 224 |
+
text = re.sub(r'([a-z])([A-Z])', r'\1 \2', text)
|
| 225 |
+
text = re.sub(r'([a-zA-Z])([0-9])', r'\1 \2', text)
|
| 226 |
+
text = re.sub(r'([0-9])([a-zA-Z])', r'\1 \2', text)
|
| 227 |
|
| 228 |
+
# μν ννμ μ²λ¦¬
|
| 229 |
def process_math(match):
|
| 230 |
content = match.group(1)
|
| 231 |
+
# μ§μ μ²λ¦¬
|
| 232 |
+
if '^' in content:
|
| 233 |
+
base, exp = content.split('^')
|
| 234 |
+
return f'${base}^{{{exp}}}$'
|
| 235 |
+
# κ³±μ
, λ§μ
λ± μ²λ¦¬
|
| 236 |
+
content = content.replace('Γ', '\\times')
|
| 237 |
+
content = content.replace('+', '+')
|
| 238 |
+
return f'${content}$'
|
| 239 |
|
| 240 |
+
# κ΄νΈ μμ μμ μ°Ύμμ μ²λ¦¬
|
| 241 |
+
text = re.sub(r'\((.*?)\)', process_math, text)
|
| 242 |
|
| 243 |
+
# LaTeX λΆλΆ 볡μ
|
| 244 |
+
for i, latex in enumerate(latex_parts):
|
| 245 |
+
text = text.replace(f"LATEX_{i}_PLACEHOLDER", latex)
|
| 246 |
|
| 247 |
return text
|
| 248 |
|