File size: 737 Bytes
3e6b063
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# controller/models/scribble_to_latex.py
import base64
from io import BytesIO
from PIL import Image
from .math_equation import image_to_latex  # reuse your existing pix2tex model

def scribble_to_latex(image_data: str):
    """

    Convert scribble (base64 PNG) to LaTeX using Pix2Text model.

    """
    try:
        # Decode base64 image
        image_bytes = base64.b64decode(image_data.split(',')[1])
        image = Image.open(BytesIO(image_bytes)).convert("RGB")

        # Call your existing model
        latex_code = image_to_latex(image)

        return latex_code.strip()
    except Exception as e:
        print(f"❌ Error in scribble_to_latex: {e}")
        return "⚠️ Failed to process scribble"