Commit ·
942de0e
1
Parent(s): a1c8dda
PUSH
Browse files- Dockerfile +11 -0
- api.py +31 -0
- requirements.txt +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.8-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
|
| 7 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 8 |
+
|
| 9 |
+
COPY . .
|
| 10 |
+
|
| 11 |
+
CMD ["python", "api.py"]
|
api.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
from rapidocr_onnxruntime import RapidOCR
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
engine = RapidOCR()
|
| 7 |
+
|
| 8 |
+
@app.route('/ocr', methods=['POST'])
|
| 9 |
+
def process_ocr():
|
| 10 |
+
if 'image' not in request.files:
|
| 11 |
+
return jsonify({'error': 'No image file provided'}), 400
|
| 12 |
+
|
| 13 |
+
text_results = []
|
| 14 |
+
|
| 15 |
+
for img_file in request.files.getlist('image'):
|
| 16 |
+
img = Image.open(img_file)
|
| 17 |
+
lebar, tinggi = img.size
|
| 18 |
+
|
| 19 |
+
potong_atas = 100
|
| 20 |
+
area_crop = (0, potong_atas, lebar, tinggi // 3)
|
| 21 |
+
img_crop = img.crop(area_crop)
|
| 22 |
+
|
| 23 |
+
result, _ = engine(img_crop)
|
| 24 |
+
|
| 25 |
+
text_array = [item[1] for item in result]
|
| 26 |
+
text_results.append(text_array)
|
| 27 |
+
|
| 28 |
+
return jsonify({'text': text_results})
|
| 29 |
+
|
| 30 |
+
if __name__ == '__main__':
|
| 31 |
+
app.run(debug=True, host='127.0.0.1', port=8080)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Flask
|
| 2 |
+
Pillow
|
| 3 |
+
rapidocr-onnxruntime
|