Skip to content

Commit

Permalink
Swap to new texify model
Browse files Browse the repository at this point in the history
  • Loading branch information
VikParuchuri committed Jan 28, 2025
1 parent e534a14 commit 5fdb25b
Showing 1 changed file with 2 additions and 31 deletions.
33 changes: 2 additions & 31 deletions marker/models.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,12 @@
import os

from marker.settings import settings

os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1" # Transformers uses .isin for a simple op, which is not supported on MPS

from typing import List
from PIL import Image
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1" # Transformers uses .isin for an op, which is not supported on MPS

from surya.detection import DetectionPredictor
from surya.layout import LayoutPredictor
from surya.ocr_error import OCRErrorPredictor
from surya.recognition import RecognitionPredictor
from surya.table_rec import TableRecPredictor

from texify.model.model import load_model as load_texify_model
from texify.model.processor import load_processor as load_texify_processor
from texify.inference import batch_inference

class TexifyPredictor:
def __init__(self, device=None, dtype=None):
if not device:
device = settings.TORCH_DEVICE_MODEL
if not dtype:
dtype = settings.TEXIFY_DTYPE

self.model = load_texify_model(checkpoint=settings.TEXIFY_MODEL_NAME, device=device, dtype=dtype)
self.processor = load_texify_processor()
self.device = device
self.dtype = dtype

def __call__(self, batch_images: List[Image.Image], max_tokens: int):
return batch_inference(
batch_images,
self.model,
self.processor,
max_tokens=max_tokens
)
from surya.texify import TexifyPredictor


def create_model_dict(device=None, dtype=None) -> dict:
Expand Down

0 comments on commit 5fdb25b

Please sign in to comment.