update
This commit is contained in:
parent
6237ff4f99
commit
48091be949
@ -4,12 +4,11 @@ FROM python:3.12.6
|
||||
#
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt /app
|
||||
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
||||
|
||||
#
|
||||
COPY . /app
|
||||
|
||||
|
||||
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
||||
|
||||
|
||||
#
|
||||
CMD ["uvicorn", "main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"]
|
23
main.py
23
main.py
@ -1,15 +1,25 @@
|
||||
import asyncio
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
import aiohttp # 用于异步 HTTP 请求
|
||||
import easyocr
|
||||
import torch
|
||||
from fastapi import FastAPI, UploadFile, File, Query
|
||||
from fastapi.responses import JSONResponse
|
||||
import easyocr
|
||||
from typing import Optional
|
||||
import asyncio
|
||||
import aiohttp # 用于异步 HTTP 请求
|
||||
|
||||
MODEL_DIR = "./models"
|
||||
USE_GPU = os.environ.get('USE_GPU', 'false') == 'true'
|
||||
NNPACK = os.environ.get('NNPACK', 'false') == 'true'
|
||||
torch.backends.nnpack.enabled = NNPACK
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
# 初始化常用的语言组合 OCR 读取器
|
||||
reader_sim = easyocr.Reader(lang_list=['ch_sim', 'en'], model_storage_directory=MODEL_DIR)
|
||||
reader_sim = easyocr.Reader(
|
||||
lang_list=['ch_sim', 'en'],
|
||||
model_storage_directory=MODEL_DIR,
|
||||
gpu=USE_GPU)
|
||||
|
||||
# 存储 OCR 读取器的缓存字典
|
||||
readers = {}
|
||||
@ -40,7 +50,8 @@ async def get_reader(lang_1: Optional[str], lang_2: Optional[str]):
|
||||
try:
|
||||
# 尝试初始化 OCR 读取器
|
||||
readers[lang_combination] = easyocr.Reader(lang_list=list(lang_combination),
|
||||
model_storage_directory=MODEL_DIR)
|
||||
model_storage_directory=MODEL_DIR,
|
||||
gpu=USE_GPU)
|
||||
except ValueError as ve:
|
||||
return None, str(ve) # 返回错误信息
|
||||
except Exception as e:
|
||||
|
@ -33,15 +33,20 @@ spec:
|
||||
claimName: easyocr-pvc
|
||||
containers:
|
||||
- name: easyocr
|
||||
image: leafdev.top/ecosystem/ocr:v0.0.1
|
||||
image: leafdev.top/ecosystem/ocr:v0.0.4
|
||||
env:
|
||||
- name: USE_GPU
|
||||
value: "false"
|
||||
- name: NNPACK
|
||||
value: "false"
|
||||
ports:
|
||||
- containerPort: 80
|
||||
protocol: TCP
|
||||
name: http
|
||||
resources:
|
||||
requests:
|
||||
cpu: 1000m
|
||||
memory: 1024Mi
|
||||
# resources:
|
||||
# requests:
|
||||
# cpu: 1000m
|
||||
# memory: 1024Mi
|
||||
volumeMounts:
|
||||
- mountPath: /app/models
|
||||
name: easyocr-models
|
||||
|
Loading…
Reference in New Issue
Block a user