Update app.py
Browse files
app.py
CHANGED
|
@@ -18,13 +18,13 @@ client = OpenAI(
|
|
| 18 |
|
| 19 |
from PIL import Image
|
| 20 |
from pix2tex import cli as pix2tex
|
| 21 |
-
|
|
|
|
| 22 |
def image_to_latex(image_path):
|
| 23 |
-
model = pix2tex.LatexOCR()
|
| 24 |
image = Image.open(image_path).convert("RGB")
|
| 25 |
-
|
| 26 |
-
return latex_code
|
| 27 |
|
|
|
|
| 28 |
# Global dictionary to store all conversations: {id: {"title": str, "messages": list}}
|
| 29 |
conversations = {}
|
| 30 |
|
|
|
|
| 18 |
|
| 19 |
from PIL import Image
|
| 20 |
from pix2tex import cli as pix2tex
|
| 21 |
+
# Load model once to avoid re-init every time
|
| 22 |
+
ocr_model = pix2tex.LatexOCR()
|
| 23 |
def image_to_latex(image_path):
|
|
|
|
| 24 |
image = Image.open(image_path).convert("RGB")
|
| 25 |
+
return ocr_model(image)
|
|
|
|
| 26 |
|
| 27 |
+
|
| 28 |
# Global dictionary to store all conversations: {id: {"title": str, "messages": list}}
|
| 29 |
conversations = {}
|
| 30 |
|