File size: 953 Bytes
942de0e
 
 
0b82dfb
942de0e
 
 
 
ba1c3ad
 
 
 
942de0e
 
 
 
 
 
 
 
 
 
 
646d98d
589c4ac
942de0e
 
0b82dfb
 
 
942de0e
 
 
 
 
 
 
0b82dfb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from flask import Flask, request, jsonify
from rapidocr_onnxruntime import RapidOCR
from PIL import Image
import numpy as np

app = Flask(__name__)
engine = RapidOCR()

@app.route('/')
def index():
    return "Welcome to the OCR API"

@app.route('/ocr', methods=['POST'])
def process_ocr():
    if 'image' not in request.files:
        return jsonify({'error': 'No image file provided'}), 400

    text_results = []

    for img_file in request.files.getlist('image'):
        img = Image.open(img_file)
        lebar, tinggi = img.size

        potong_atas = 201
        area_crop = (0, potong_atas, lebar, tinggi // 2)
        img_crop = img.crop(area_crop)

        img_array = np.array(img_crop)

        result, _ = engine(img_array)

        text_array = [item[1] for item in result]
        text_results.append(text_array)

    return jsonify({'text': text_results})

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=7860, debug=True)