Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,8 @@ from src.SecondModule.module2 import SimilarQuestionGenerator
|
|
5 |
from src.ThirdModule.module3 import AnswerVerifier
|
6 |
import logging
|
7 |
from typing import Optional, Tuple
|
|
|
|
|
8 |
logging.basicConfig(level=logging.DEBUG)
|
9 |
|
10 |
|
@@ -183,90 +185,18 @@ def handle_answer(answer, current_q):
|
|
183 |
if st.session_state.current_question_index >= 10:
|
184 |
st.session_state.current_step = 'review'
|
185 |
|
186 |
-
|
187 |
-
|
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):
|
208 |
"""์ํ ๋ด์ฉ์ ํ๋ฉด์ ํ์"""
|
209 |
-
formatted_content =
|
210 |
-
# LaTeX ๋ ๋๋ง์ ์ํ ์ถ๊ฐ ์ค์
|
211 |
st.markdown(formatted_content, unsafe_allow_html=True)
|
212 |
|
213 |
-
def
|
214 |
-
"""
|
215 |
-
|
216 |
-
|
217 |
-
# LaTeX ํน์ ๋ช
๋ น์ด ๋งคํ
|
218 |
-
latex_commands = {
|
219 |
-
r'\left': r'\\left',
|
220 |
-
r'\right': r'\\right',
|
221 |
-
r'\bigcirc': r'\\bigcirc',
|
222 |
-
r'\square': r'\\square',
|
223 |
-
r'\quad': r'\\quad'
|
224 |
-
}
|
225 |
-
|
226 |
-
# 1. ์ด๋ฏธ ์กด์ฌํ๋ LaTeX ์์ ๋ณด์กด
|
227 |
-
latex_parts = []
|
228 |
-
def save_latex(match):
|
229 |
-
latex_parts.append(match.group(0))
|
230 |
-
return f"LATEX_{len(latex_parts)-1}_PLACEHOLDER"
|
231 |
-
|
232 |
-
text = re.sub(r'\$\$.*?\$\$', save_latex, text)
|
233 |
-
|
234 |
-
# 2. ํน์ ๋ช
๋ น์ด ์ฒ๋ฆฌ
|
235 |
-
for cmd, latex_cmd in latex_commands.items():
|
236 |
-
text = text.replace(cmd, latex_cmd)
|
237 |
-
|
238 |
-
# 3. ๋ถ์ด์๋ ๋จ์ด ๋ถ๋ฆฌ
|
239 |
-
text = re.sub(r'([a-z])([A-Z])', r'\1 \2', text)
|
240 |
-
text = re.sub(r'([A-Za-z])(\d)', r'\1 \2', text)
|
241 |
-
text = re.sub(r'(\d)([A-Za-z])', r'\1 \2', text)
|
242 |
-
|
243 |
-
# 4. ๋ฌธ์ฅ ๋ถ์
|
244 |
-
sentences = text.split('$$')
|
245 |
-
formatted_sentences = []
|
246 |
-
|
247 |
-
for i, sentence in enumerate(sentences):
|
248 |
-
if i % 2 == 0: # ์ผ๋ฐ ํ
์คํธ
|
249 |
-
# ์์์ด ์๋ ๋ถ๋ถ์ ํน์ ๋ฌธ์ ์ฒ๋ฆฌ
|
250 |
-
for cmd, latex_cmd in latex_commands.items():
|
251 |
-
if cmd in sentence:
|
252 |
-
sentence = f"$${sentence}$$"
|
253 |
-
break
|
254 |
-
formatted_sentences.append(sentence)
|
255 |
-
else: # ์์
|
256 |
-
formatted_sentences.append(f"$${sentence}$$")
|
257 |
-
|
258 |
-
text = ''.join(formatted_sentences)
|
259 |
-
|
260 |
-
# 5. LaTeX ์์ ๋ณต์
|
261 |
-
for i, latex in enumerate(latex_parts):
|
262 |
-
text = text.replace(f"LATEX_{i}_PLACEHOLDER", latex)
|
263 |
-
|
264 |
-
# 6. ๋ง์ง๋ง ์ ๋ฆฌ
|
265 |
-
text = text.replace('\\\\', '\\') # ์ค๋ณต๋ ๋ฐฑ์ฌ๋์ ์ ๊ฑฐ
|
266 |
-
text = re.sub(r'\s+', ' ', text) # ์ฌ๋ฌ ๊ฐ์ ๊ณต๋ฐฑ์ ํ๋๋ก
|
267 |
-
|
268 |
-
return text
|
269 |
-
|
270 |
def main():
|
271 |
"""๋ฉ์ธ ์ ํ๋ฆฌ์ผ์ด์
๋ก์ง"""
|
272 |
st.title("MisconcepTutor")
|
|
|
5 |
from src.ThirdModule.module3 import AnswerVerifier
|
6 |
import logging
|
7 |
from typing import Optional, Tuple
|
8 |
+
from latex_formatter import LatexFormatter # LaTeX ํฌ๋งทํฐ import
|
9 |
+
|
10 |
logging.basicConfig(level=logging.DEBUG)
|
11 |
|
12 |
|
|
|
185 |
if st.session_state.current_question_index >= 10:
|
186 |
st.session_state.current_step = 'review'
|
187 |
|
188 |
+
# ์ ์ญ LaTeX ํฌ๋งทํฐ ์ธ์คํด์ค ์์ฑ
|
189 |
+
latex_formatter = LatexFormatter()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
|
191 |
def display_math_content(content: str):
|
192 |
"""์ํ ๋ด์ฉ์ ํ๋ฉด์ ํ์"""
|
193 |
+
formatted_content = latex_formatter.format_expression(content)
|
|
|
194 |
st.markdown(formatted_content, unsafe_allow_html=True)
|
195 |
|
196 |
+
def format_answer_choice(choice: str) -> str:
|
197 |
+
"""์ ํ์ง LaTeX ํฌ๋งทํ
"""
|
198 |
+
return latex_formatter.format_expression(choice)
|
199 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
def main():
|
201 |
"""๋ฉ์ธ ์ ํ๋ฆฌ์ผ์ด์
๋ก์ง"""
|
202 |
st.title("MisconcepTutor")
|