HycJack commited on
Commit
1cdc160
1 Parent(s): 08606b0
Files changed (3) hide show
  1. Dockerfile +1 -1
  2. main.py +16 -1
  3. requirements.txt +3 -1
Dockerfile CHANGED
@@ -8,4 +8,4 @@ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
 
9
  COPY . .
10
 
11
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
8
 
9
  COPY . .
10
 
11
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py CHANGED
@@ -1,7 +1,22 @@
1
  from fastapi import FastAPI
2
 
3
  app = FastAPI()
 
 
 
 
4
 
5
  @app.get("/")
6
  def read_root():
7
- return {"Hello": "World!"}
 
 
 
 
 
 
 
 
 
 
 
 
1
  from fastapi import FastAPI
2
 
3
  app = FastAPI()
4
+ from rapidocr_onnxruntime import RapidOCR
5
+
6
+ # det_model_path同理
7
+ model = RapidOCR()
8
 
9
  @app.get("/")
10
  def read_root():
11
+ return {"Hello": "World!"}
12
+
13
+ @app.post("/ocr")
14
+ async def ocr(file: UploadFile = File(...)):
15
+ # 读取上传的文件内容
16
+ contents = await file.read()
17
+ # 使用Pillow打开图像
18
+ image = Image.open(io.BytesIO(contents))
19
+ # 将图像转换为numpy数组
20
+ np_array = np.array(image)
21
+ result, elapse = model(np_array)
22
+ return result
requirements.txt CHANGED
@@ -4,4 +4,6 @@ sentencepiece==0.1.*
4
  torch==1.11.*
5
  transformers==4.*
6
  uvicorn[standard]==0.17.*
7
-
 
 
 
4
  torch==1.11.*
5
  transformers==4.*
6
  uvicorn[standard]==0.17.*
7
+ Pillow
8
+ onnxruntime
9
+ rapidocr_onnxruntime