replicate / cog

Containers for machine learning
https://cog.run
Apache License 2.0
7.53k stars 522 forks source link

Got ImportError in cog while installing packages from surya-ocr ImportError: cannot import name 'computed_field' from 'pydantic' (/usr/local/lib/python3.11/site-packages/pydantic/ #1697

Open anilpatelia opened 1 month ago

anilpatelia commented 1 month ago

Hi,

I am working on surya-ocr using cog [https://replicate.com/cudanexus/ocr-surya]. The image is building successfully but when I run the docker image file I get Import Error.

The error is below:

Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/cog/server/worker.py", line 186, in _setup
self._predictor = load_predictor_from_ref(self._predictor_ref)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/cog/predictor.py", line 248, in load_predictor_from_ref
module = load_full_predictor_from_file(module_path, module_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/cog/predictor.py", line 200, in load_full_predictor_from_file
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/src/predict.py", line 7, in <module>
from surya.ocr import run_ocr
File "/usr/local/lib/python3.11/site-packages/surya/ocr.py", line 4, in <module>
from surya.detection import batch_text_detection
File "/usr/local/lib/python3.11/site-packages/surya/detection.py", line 7, in <module>
from surya.model.detection.segformer import SegformerForRegressionMask
File "/usr/local/lib/python3.11/site-packages/surya/model/detection/segformer.py", line 14, in <module>
from surya.settings import settings
File "/usr/local/lib/python3.11/site-packages/surya/settings.py", line 4, in <module>
from pydantic import computed_field
ImportError: cannot import name 'computed_field' from 'pydantic' (/usr/local/lib/python3.11/site-packages/pydantic/__init__.cpython-311-x86_64-linux-gnu.so)

The cog.yaml file: build:

set to true if your model requires a GPU

gpu: true

a list of ubuntu apt packages to install

system_packages:

- "libgl1-mesa-glx"

- "libglib2.0-0"

python version in the form '3.11' or '3.11.4'

python_version: "3.11"

a list of packages in the format ==

python_packages:

predict.py defines how predictions are run on your model

predict: "predict.py:Predictor"

The part of predict.py file:

from PIL import Image
from surya.ocr import run_ocr
from surya.model.detection import segformer
from surya.model.recognition.model import load_model
from surya.model.recognition.processor import load_processor

Please help for above issue.

martin-sn commented 4 weeks ago

I am having this issue as well, seems to be related to #1562