tex2lab / controller /models /scribble_to_latex.py
Zunayedthebot's picture
Upload 132 files
3e6b063 verified
# 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"