Update app.py
Browse files
app.py
CHANGED
|
@@ -84,7 +84,12 @@ def solve_simultaneous_equations(img):
|
|
| 84 |
latex_result = model(img)
|
| 85 |
cleaned_latex = clean_latex(latex_result)
|
| 86 |
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
if len(lines) < 2:
|
| 89 |
return f"β Expected at least 2 equations but found {len(lines)}.\n\nExtracted:\n{cleaned_latex}"
|
| 90 |
|
|
@@ -92,12 +97,15 @@ def solve_simultaneous_equations(img):
|
|
| 92 |
symbols = set()
|
| 93 |
|
| 94 |
for line in lines:
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
if len(symbols) < 2:
|
| 103 |
return f"β Need at least 2 variables to solve system. Found: {symbols}"
|
|
|
|
| 84 |
latex_result = model(img)
|
| 85 |
cleaned_latex = clean_latex(latex_result)
|
| 86 |
|
| 87 |
+
# Extract lines: handle environments or normal newlines
|
| 88 |
+
if 'begin{array}' in cleaned_latex or 'begin{aligned}' in cleaned_latex:
|
| 89 |
+
lines = re.findall(r'(.*?)\\\\', cleaned_latex + '\\\\') # Append fake end to catch last line
|
| 90 |
+
else:
|
| 91 |
+
lines = [line.strip() for line in cleaned_latex.split('\n') if line.strip()]
|
| 92 |
+
|
| 93 |
if len(lines) < 2:
|
| 94 |
return f"β Expected at least 2 equations but found {len(lines)}.\n\nExtracted:\n{cleaned_latex}"
|
| 95 |
|
|
|
|
| 97 |
symbols = set()
|
| 98 |
|
| 99 |
for line in lines:
|
| 100 |
+
try:
|
| 101 |
+
parsed = parse_latex(line)
|
| 102 |
+
if not isinstance(parsed, sp.Equality):
|
| 103 |
+
return f"β Failed to parse line as equation: {line}"
|
| 104 |
+
lhs = parsed.lhs - parsed.rhs
|
| 105 |
+
symbols.update(lhs.free_symbols)
|
| 106 |
+
equations.append(lhs)
|
| 107 |
+
except Exception as e:
|
| 108 |
+
return f"β Error parsing line: `{line}`\n{str(e)}"
|
| 109 |
|
| 110 |
if len(symbols) < 2:
|
| 111 |
return f"β Need at least 2 variables to solve system. Found: {symbols}"
|