Yitshak commited on
Commit
5b739e4
·
verified ·
1 Parent(s): ba4cc05

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +18 -0
  2. main.py +27 -0
  3. requirements.txt +7 -0
Dockerfile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ RUN apt-get update && apt-get install -y \
4
+ libglib2.0-0 libsm6 libxrender1 libxext6 libgl1 libgomp1 \
5
+ && rm -rf /var/lib/apt/lists/*
6
+
7
+ WORKDIR /app
8
+
9
+ COPY requirements.txt .
10
+ RUN pip install --no-cache-dir -r requirements.txt
11
+
12
+ # Download model saat build, bukan saat runtime
13
+ RUN python -c "from paddleocr import PaddleOCR; PaddleOCR(use_angle_cls=True, lang='en', use_gpu=False)"
14
+
15
+ COPY . .
16
+
17
+ EXPOSE 7860
18
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, UploadFile, File
2
+ from paddleocr import PaddleOCR
3
+ from PIL import Image
4
+ import io, numpy as np
5
+
6
+ app = FastAPI()
7
+ ocr = PaddleOCR(use_angle_cls=True, lang='en', use_gpu=False)
8
+
9
+ @app.get("/")
10
+ def health():
11
+ return {"status": "ok"}
12
+
13
+ @app.post("/ocr")
14
+ async def run_ocr(file: UploadFile = File(...)):
15
+ contents = await file.read()
16
+ image = Image.open(io.BytesIO(contents)).convert("RGB")
17
+ img_array = np.array(image)
18
+ result = ocr.ocr(img_array, cls=True)
19
+
20
+ texts = []
21
+ for line in result[0]:
22
+ texts.append({
23
+ "text": line[1][0],
24
+ "confidence": round(line[1][1], 4)
25
+ })
26
+
27
+ return {"filename": file.filename, "results": texts}
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ fastapi==0.111.0
2
+ uvicorn==0.30.1
3
+ paddlepaddle==2.6.1
4
+ paddleocr==2.7.3
5
+ python-multipart==0.0.9
6
+ pillow==10.3.0
7
+ numpy==1.26.4