MasteredUltraInstinct commited on
Commit
e44317b
Β·
verified Β·
1 Parent(s): ef5c42f

Update image.py

Browse files
Files changed (1) hide show
  1. image.py +12 -2
image.py CHANGED
@@ -8,6 +8,8 @@ import re
8
  import io
9
  import logging
10
  from llm_utils import explain_with_llm # βœ… Added for LLM explanation
 
 
11
 
12
  # Configure logging for debugging
13
  logging.basicConfig(level=logging.INFO)
@@ -40,6 +42,13 @@ def clean_latex_expression(latex_str):
40
  if '=' in latex_str:
41
  left, right = latex_str.split('=')
42
  latex_str = f"{left} - ({right})" # Move right-hand side to left
 
 
 
 
 
 
 
43
  return latex_str.strip()
44
 
45
  def parse_equation_type(latex_str):
@@ -295,14 +304,15 @@ def solve_linear_system_from_coeffs(eq1_str, eq2_str):
295
 
296
  def solve_extracted_equation(eq_data, real_only):
297
  if eq_data["type"] == "polynomial":
298
- return solve_polynomial(eq_data["degree"], eq_data["coeffs"], real_only)
299
  elif eq_data["type"] == "linear":
300
  return "❌ Single linear equation not supported. Please upload a system of equations.", None, ""
301
  elif eq_data["type"] == "linear_system":
302
- return solve_linear_system_from_coeffs(eq_data["eq1_coeffs"], eq_data["eq2_coeffs"])
303
  else:
304
  return "❌ Unknown equation type", None, ""
305
 
 
306
  def image_tab():
307
  """Create the Image Upload Solver tab"""
308
  with gr.Tab("Image Upload Solver"):
 
8
  import io
9
  import logging
10
  from llm_utils import explain_with_llm # βœ… Added for LLM explanation
11
+ from solver import solve_polynomial as solve_poly_from_solver, solve_linear_system as solve_sys_from_solver
12
+
13
 
14
  # Configure logging for debugging
15
  logging.basicConfig(level=logging.INFO)
 
42
  if '=' in latex_str:
43
  left, right = latex_str.split('=')
44
  latex_str = f"{left} - ({right})" # Move right-hand side to left
45
+
46
+ # Add missing multiplication: (expr)x β†’ (expr)*x
47
+ latex_str = re.sub(r'(\))([a-zA-Z])', r'\1*\2', latex_str)
48
+
49
+ # Add * between number/symbol and parenthesis: e.g., 3( β†’ 3*(...
50
+ latex_str = re.sub(r'(\d|\w)\(', r'\1*(', latex_str)
51
+
52
  return latex_str.strip()
53
 
54
  def parse_equation_type(latex_str):
 
304
 
305
  def solve_extracted_equation(eq_data, real_only):
306
  if eq_data["type"] == "polynomial":
307
+ return solve_poly_from_solver(eq_data["degree"], eq_data["coeffs"])
308
  elif eq_data["type"] == "linear":
309
  return "❌ Single linear equation not supported. Please upload a system of equations.", None, ""
310
  elif eq_data["type"] == "linear_system":
311
+ return solve_sys_from_solver(eq_data["eq1_coeffs"], eq_data["eq2_coeffs"])
312
  else:
313
  return "❌ Unknown equation type", None, ""
314
 
315
+
316
  def image_tab():
317
  """Create the Image Upload Solver tab"""
318
  with gr.Tab("Image Upload Solver"):