Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -188,45 +188,79 @@ def format_math_expression(text: str) -> str:
|
|
188 |
"""์ํ ํํ์์ LaTeX ํ์์ผ๋ก ๋ณํ"""
|
189 |
import re
|
190 |
|
191 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
replacements = {
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
}
|
199 |
|
200 |
-
# ๋ถ์ ํจํด ์ฐพ๊ธฐ
|
201 |
text = re.sub(r'(\d+)/(\d+)', r'\\frac{\1}{\2}', text)
|
202 |
|
203 |
-
#
|
204 |
-
text = re.sub(r'\(
|
205 |
|
206 |
-
#
|
|
|
|
|
|
|
207 |
for old, new in replacements.items():
|
208 |
text = text.replace(old, new)
|
209 |
|
210 |
-
#
|
211 |
def wrap_math(match):
|
212 |
expr = match.group(1)
|
213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
|
215 |
-
#
|
216 |
-
|
|
|
|
|
|
|
217 |
|
218 |
return text
|
219 |
|
220 |
def display_math_question(question: str):
|
221 |
"""์ํ ๋ฌธ์ ๋ฅผ LaTeX ํ์์ผ๋ก ํ์"""
|
222 |
formatted_question = format_math_expression(question)
|
223 |
-
st.markdown(formatted_question)
|
|
|
|
|
|
|
|
|
224 |
|
225 |
def display_math_answer(answer: str):
|
226 |
"""์ํ ๋ต์์ LaTeX ํ์์ผ๋ก ํ์"""
|
227 |
formatted_answer = format_math_expression(answer)
|
228 |
# ๊ดํธ ์์ ์์๋ง LaTeX๋ก ์ฒ๋ฆฌ
|
229 |
st.markdown(formatted_answer)
|
|
|
|
|
230 |
def main():
|
231 |
"""๋ฉ์ธ ์ ํ๋ฆฌ์ผ์ด์
๋ก์ง"""
|
232 |
st.title("MisconcepTutor")
|
|
|
188 |
"""์ํ ํํ์์ LaTeX ํ์์ผ๋ก ๋ณํ"""
|
189 |
import re
|
190 |
|
191 |
+
# LaTeX ํ ์ฒ๋ฆฌ
|
192 |
+
def format_table(match):
|
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 = re.sub(r'\\begin{tabular}(.*?)\\end{tabular}', format_table, text, flags=re.DOTALL)
|
200 |
+
|
201 |
+
# ๊ธฐ๋ณธ ์ํ ๊ธฐํธ ๋ณํ
|
202 |
replacements = {
|
203 |
+
'รท': '\\div',
|
204 |
+
'ร': '\\times',
|
205 |
+
'*': '\\cdot', # ๊ณฑ์
์
|
206 |
+
'โ ': '\\neq',
|
207 |
+
'โค': '\\leq',
|
208 |
+
'โฅ': '\\geq',
|
209 |
+
'โ': '\\rightarrow',
|
210 |
+
'โ': '\\leftarrow',
|
211 |
+
'ยฑ': '\\pm',
|
212 |
+
'โ': '\\infty',
|
213 |
+
'โ': '\\sqrt',
|
214 |
}
|
215 |
|
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 |
+
# ๊ดํธ ์์ ์์์ LaTeX๋ก ์ฒ๋ฆฌ
|
230 |
def wrap_math(match):
|
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)
|
251 |
+
st.markdown(formatted_question, unsafe_allow_html=True)
|
252 |
+
|
253 |
+
def format_math_choices(choices: dict) -> dict:
|
254 |
+
"""์ ํ์ง์ ์ํ ํํ์์ LaTeX ํ์์ผ๋ก ๋ณํ"""
|
255 |
+
return {k: format_math_expression(v) for k, v in choices.items()}
|
256 |
|
257 |
def display_math_answer(answer: str):
|
258 |
"""์ํ ๋ต์์ LaTeX ํ์์ผ๋ก ํ์"""
|
259 |
formatted_answer = format_math_expression(answer)
|
260 |
# ๊ดํธ ์์ ์์๋ง LaTeX๋ก ์ฒ๋ฆฌ
|
261 |
st.markdown(formatted_answer)
|
262 |
+
|
263 |
+
|
264 |
def main():
|
265 |
"""๋ฉ์ธ ์ ํ๋ฆฌ์ผ์ด์
๋ก์ง"""
|
266 |
st.title("MisconcepTutor")
|