Spaces:
Build error
Build error
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 |
# ๋ณต์ต ํ๋ฉด
|