Update app.py
Browse files
app.py
CHANGED
|
@@ -84,9 +84,14 @@ def solve_simultaneous_equations(img):
|
|
| 84 |
latex_result = model(img)
|
| 85 |
cleaned_latex = clean_latex(latex_result)
|
| 86 |
|
| 87 |
-
# Extract lines:
|
| 88 |
-
if '
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
else:
|
| 91 |
lines = [line.strip() for line in cleaned_latex.split('\n') if line.strip()]
|
| 92 |
|
|
@@ -139,10 +144,6 @@ with gr.Blocks() as demo:
|
|
| 139 |
output_box = gr.Markdown(label="๐ Step-by-step Solution")
|
| 140 |
submit_btn = gr.Button("๐ Solve")
|
| 141 |
submit_btn.click(fn=wrapped_solver, inputs=[image_input], outputs=[output_box, hidden_latex, explanation_prompt])
|
| 142 |
-
# Human explanation (commented out)
|
| 143 |
-
# explain_box = gr.Markdown(label="๐ฃ๏ธ Human-style Explanation")
|
| 144 |
-
# explain_btn = gr.Button("๐ง Explain Human-Solution")
|
| 145 |
-
# explain_btn.click(fn=request_llm_explanation, inputs=[explanation_prompt, llm_url], outputs=explain_box)
|
| 146 |
|
| 147 |
with gr.Tab("๐งฎ Simultaneous Equations"):
|
| 148 |
sim_image_input = gr.Image(type="pil", label="๐ท Upload Image with 2 or 3 Linear Equations")
|
|
|
|
| 84 |
latex_result = model(img)
|
| 85 |
cleaned_latex = clean_latex(latex_result)
|
| 86 |
|
| 87 |
+
# Extract lines: fix missing `\\` from array or aligned environments
|
| 88 |
+
if 'beginarray' in cleaned_latex or 'begin{aligned}' in cleaned_latex:
|
| 89 |
+
body = re.sub(r'\\?begin\{?array\}?|\\?end\{?array\}?', '', cleaned_latex)
|
| 90 |
+
if '\\\\' not in cleaned_latex:
|
| 91 |
+
# Fallback: separate equations if `\\` missing
|
| 92 |
+
lines = re.findall(r'[^=]+=.*?(?=[a-zA-Z]|$)', body)
|
| 93 |
+
else:
|
| 94 |
+
lines = re.findall(r'(.*?)\\\\', body + '\\\\')
|
| 95 |
else:
|
| 96 |
lines = [line.strip() for line in cleaned_latex.split('\n') if line.strip()]
|
| 97 |
|
|
|
|
| 144 |
output_box = gr.Markdown(label="๐ Step-by-step Solution")
|
| 145 |
submit_btn = gr.Button("๐ Solve")
|
| 146 |
submit_btn.click(fn=wrapped_solver, inputs=[image_input], outputs=[output_box, hidden_latex, explanation_prompt])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
with gr.Tab("๐งฎ Simultaneous Equations"):
|
| 149 |
sim_image_input = gr.Image(type="pil", label="๐ท Upload Image with 2 or 3 Linear Equations")
|