вот код
Код: Выделить всё
from doctr.io import DocumentFile
from doctr.models import ocr_predictor
__version__ = "0.1.1"
model = ocr_predictor(pretrained=True)
def process_image(image_path):
document = DocumentFile.from_images(image_path)
result = model(document)
json_response = result.export()
return json_response
Файл main.py, в котором установлен мой код API
Код: Выделить всё
from app.model.model import __version__ as model_version
from app.model.model import process_image
from fastapi import FastAPI, HTTPException, UploadFile
app = FastAPI()
@app.get("/")
def home():
return {"health_check": "OK", "model_version": 'model_version'}
Код: Выделить всё
uvicorn app.main:app --reload
но когда я пытался докеризировать его, он просто зависал навсегда, и вот мой Dockerfile
Код: Выделить всё
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
RUN apt-get update
RUN apt install -y libgl1-mesa-glx
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
COPY ./app /app/app
Я попробовал все, чтобы все заработало, включая перемещение импорта внутри функции.
Код: Выделить всё
__version__ = "0.1.1"
def process_image(image_path):
from doctr.io import DocumentFile
from doctr.models import ocr_predictor
model = ocr_predictor(pretrained=True)
document = DocumentFile.from_images(image_path)
result = model(document)
json_response = result.export()
return json_response
Подробнее здесь: https://stackoverflow.com/questions/775 ... gs-forever