Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion pix2tex/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from http import HTTPStatus
from fastapi import FastAPI, File, UploadFile, Form
from PIL import Image
from PIL import Image, ImageGrab
from io import BytesIO
from pix2tex.cli import LatexOCR

Expand Down Expand Up @@ -62,3 +62,14 @@ async def predict_from_bytes(file: bytes = File(...)) -> str: # , size: str = F
#size = tuple(int(a) for a in size.split(','))
image = Image.open(BytesIO(file))
return model(image, resize=False)

@app.post("/clipboard/")
async def clipboard() -> str:
"""Predict the Latex code from clipboard contents.

Returns:
str: Latex prediction
"""
global model
image = ImageGrab.grabclipboard()
return model(image)