Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -184,25 +184,44 @@ def handle_answer(answer, current_q):
|
|
| 184 |
st.session_state.current_step = 'review'
|
| 185 |
|
| 186 |
# ์์ ํํ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
def format_math_expression(text: str) -> str:
|
| 188 |
"""์ํ ํํ์์ LaTeX ํ์์ผ๋ก ๋ณํ"""
|
| 189 |
import re
|
| 190 |
|
| 191 |
-
#
|
| 192 |
-
|
| 193 |
-
table_content = match.group(1)
|
| 194 |
-
# ํ ๋ด์ฉ์ LaTeX ํ์์ผ๋ก ์ ๋ฆฌ
|
| 195 |
-
formatted_table = table_content.replace('\\\\', '\n')
|
| 196 |
-
return f'$$\\begin{{array}}{{|c|c|}} \\hline {formatted_table} \\hline \\end{{array}}$$'
|
| 197 |
|
| 198 |
-
# ๊ธฐ์กด LaTeX
|
| 199 |
-
text
|
|
|
|
| 200 |
|
| 201 |
# ๊ธฐ๋ณธ ์ํ ๊ธฐํธ ๋ณํ
|
| 202 |
replacements = {
|
| 203 |
'รท': '\\div',
|
| 204 |
'ร': '\\times',
|
| 205 |
-
'*': '\\cdot',
|
| 206 |
'โ ': '\\neq',
|
| 207 |
'โค': '\\leq',
|
| 208 |
'โฅ': '\\geq',
|
|
@@ -216,35 +235,24 @@ def format_math_expression(text: str) -> str:
|
|
| 216 |
# ๋ถ์ ํจํด ์ฐพ๊ธฐ ๋ฐ ๋ณํ
|
| 217 |
text = re.sub(r'(\d+)/(\d+)', r'\\frac{\1}{\2}', text)
|
| 218 |
|
| 219 |
-
# y=mx+b ํํ์ ๋ฐฉ์ ์ ์ฒ๋ฆฌ
|
| 220 |
-
text = re.sub(r'y\s*=\s*([-\d.]+)x\s*([+-]\s*\d+)?', r'y = \1x\2', text)
|
| 221 |
-
|
| 222 |
-
# ํํ์ ๋ด์ ๋ณ์ ์ดํค๋ฆญ์ฒด๋ก ๋ณํ
|
| 223 |
-
text = re.sub(r'([a-zA-Z])(\d*)', r'{\1}\2', text)
|
| 224 |
-
|
| 225 |
# ์ํ ๊ธฐํธ ๋ณํ
|
| 226 |
for old, new in replacements.items():
|
| 227 |
text = text.replace(old, new)
|
| 228 |
|
| 229 |
-
#
|
| 230 |
-
|
| 231 |
-
expr = match.group(1)
|
| 232 |
-
# ์ด๋ฏธ LaTeX ๋ฌ๋ฌ ๊ธฐํธ๊ฐ ์๋์ง ํ์ธ
|
| 233 |
-
if not expr.startswith('$') and not expr.endswith('$'):
|
| 234 |
-
return f'$${expr}$$'
|
| 235 |
-
return expr
|
| 236 |
-
|
| 237 |
-
# ๊ดํธ๋ก ๋๋ฌ์ธ์ธ ์์ ์ฐพ์์ LaTeX๋ก ๋ณํ
|
| 238 |
-
text = re.sub(r'\((.*?)\)', wrap_math, text)
|
| 239 |
-
|
| 240 |
-
# ์ด๋ฏธ LaTeX๋ก ์ฒ๋ฆฌ๋ ๋ถ๋ถ์ ๊ฑด๋๋ฐ๊ณ , ๋๋จธ์ง ์์์ LaTeX๋ก ์ฒ๋ฆฌ
|
| 241 |
-
def add_math_delimiters(text):
|
| 242 |
-
if '$$' not in text and '$' not in text:
|
| 243 |
-
return f'$${text}$$'
|
| 244 |
-
return text
|
| 245 |
|
| 246 |
return text
|
| 247 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
def display_math_question(question: str):
|
| 249 |
"""์ํ ๋ฌธ์ ๋ฅผ LaTeX ํ์์ผ๋ก ํ์"""
|
| 250 |
formatted_question = format_math_expression(question)
|
|
|
|
| 184 |
st.session_state.current_step = 'review'
|
| 185 |
|
| 186 |
# ์์ ํํ
|
| 187 |
+
def clean_text(text: str) -> str:
|
| 188 |
+
"""ํ
์คํธ ์ ์ฒ๋ฆฌ: ๋ถํ์ํ ์ค๊ดํธ ์ ๊ฑฐ ๋ฐ ๊ธฐ๋ณธ ํด๋ฆฌ๋"""
|
| 189 |
+
import re
|
| 190 |
+
|
| 191 |
+
# LaTeX ์์ ๋ถ๋ถ์ ์์ ์ ์ฅ
|
| 192 |
+
latex_parts = []
|
| 193 |
+
def save_latex(match):
|
| 194 |
+
latex_parts.append(match.group(0))
|
| 195 |
+
return f"LATEX_{len(latex_parts)-1}_PLACEHOLDER"
|
| 196 |
+
|
| 197 |
+
# LaTeX ์์ ๋ถ๋ถ์ ์์๋ก ์นํ
|
| 198 |
+
text = re.sub(r'\$\$.*?\$\$', save_latex, text)
|
| 199 |
+
|
| 200 |
+
# ๊ฐ ๋ฌธ์๋ฅผ ๊ฐ์ธ๊ณ ์๋ ์ค๊ดํธ ์ ๊ฑฐ
|
| 201 |
+
text = re.sub(r'\{(\w)\}', r'\1', text)
|
| 202 |
+
|
| 203 |
+
# LaTeX ์์ ๋ถ๋ถ ๋ณต์
|
| 204 |
+
for i, latex in enumerate(latex_parts):
|
| 205 |
+
text = text.replace(f"LATEX_{i}_PLACEHOLDER", latex)
|
| 206 |
+
|
| 207 |
+
return text
|
| 208 |
+
|
| 209 |
def format_math_expression(text: str) -> str:
|
| 210 |
"""์ํ ํํ์์ LaTeX ํ์์ผ๋ก ๋ณํ"""
|
| 211 |
import re
|
| 212 |
|
| 213 |
+
# ํ
์คํธ ์ ์ฒ๋ฆฌ
|
| 214 |
+
text = clean_text(text)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
+
# ๊ธฐ์กด LaTeX ํํ์์ ๋ณด์กด
|
| 217 |
+
if text.startswith('$$') and text.endswith('$$'):
|
| 218 |
+
return text
|
| 219 |
|
| 220 |
# ๊ธฐ๋ณธ ์ํ ๊ธฐํธ ๋ณํ
|
| 221 |
replacements = {
|
| 222 |
'รท': '\\div',
|
| 223 |
'ร': '\\times',
|
| 224 |
+
'*': '\\cdot',
|
| 225 |
'โ ': '\\neq',
|
| 226 |
'โค': '\\leq',
|
| 227 |
'โฅ': '\\geq',
|
|
|
|
| 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 |
+
# ์ง์ ํํ ์ฒ๋ฆฌ (์: x^2)
|
| 243 |
+
text = re.sub(r'(\d+)\^(\d+)', r'$$\1^{\2}$$', text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
return text
|
| 246 |
|
| 247 |
+
def display_math_question(question: str):
|
| 248 |
+
"""์ํ ๋ฌธ์ ๋ฅผ LaTeX ํ์์ผ๋ก ํ์"""
|
| 249 |
+
formatted_question = format_math_expression(question)
|
| 250 |
+
st.markdown(formatted_question)
|
| 251 |
+
|
| 252 |
+
def format_math_choices(choices: dict) -> dict:
|
| 253 |
+
"""์ ํ์ง์ ์ํ ํํ์์ LaTeX ํ์์ผ๋ก ๋ณํ"""
|
| 254 |
+
return {k: format_math_expression(v) for k, v in choices.items()}
|
| 255 |
+
|
| 256 |
def display_math_question(question: str):
|
| 257 |
"""์ํ ๋ฌธ์ ๋ฅผ LaTeX ํ์์ผ๋ก ํ์"""
|
| 258 |
formatted_question = format_math_expression(question)
|