update
This commit is contained in:
parent
7688e822d6
commit
fb03a380db
2
.gitignore
vendored
2
.gitignore
vendored
@ -321,3 +321,5 @@ cython_debug/
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
# Model files
|
||||
models
|
@ -2,9 +2,10 @@
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.idea/httpRequests" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.12 (ocr)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
6
main.py
6
main.py
@ -5,10 +5,11 @@ from typing import Optional
|
||||
import asyncio
|
||||
import aiohttp # 用于异步 HTTP 请求
|
||||
|
||||
MODEL_DIR = "./models"
|
||||
app = FastAPI()
|
||||
|
||||
# 初始化常用的语言组合 OCR 读取器
|
||||
reader_sim = easyocr.Reader(['ch_sim', 'en'])
|
||||
reader_sim = easyocr.Reader(lang_list=['ch_sim', 'en'], model_storage_directory=MODEL_DIR)
|
||||
|
||||
# 存储 OCR 读取器的缓存字典
|
||||
readers = {}
|
||||
@ -38,7 +39,8 @@ async def get_reader(lang_1: Optional[str], lang_2: Optional[str]):
|
||||
if lang_combination not in readers:
|
||||
try:
|
||||
# 尝试初始化 OCR 读取器
|
||||
readers[lang_combination] = easyocr.Reader(list(lang_combination))
|
||||
readers[lang_combination] = easyocr.Reader(lang_list=list(lang_combination),
|
||||
model_storage_directory=MODEL_DIR)
|
||||
except ValueError as ve:
|
||||
return None, str(ve) # 返回错误信息
|
||||
except Exception as e:
|
||||
|
1419
poetry.lock
generated
Normal file
1419
poetry.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
18
pyproject.toml
Normal file
18
pyproject.toml
Normal file
@ -0,0 +1,18 @@
|
||||
[project]
|
||||
name = "ocr"
|
||||
[tool.poetry]
|
||||
name = "ocr"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.12"
|
||||
fastapi = "^0.115.0"
|
||||
easyocr = "^1.7.2"
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
Loading…
Reference in New Issue
Block a user