File size: 656 Bytes
5b74dbd
 
b6edd87
 
 
5b74dbd
 
 
 
 
 
ac57661
 
 
 
 
5b74dbd
 
 
 
 
 
 
 
 
b6edd87
5b74dbd
 
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
from flask import Flask, request, jsonify
import easyocr
from PIL import Image
import base64
from io import BytesIO

app = Flask(__name__)

reader = easyocr.Reader(['ja', 'en'])


@app.route("/")
def index():
    return "hello"


@app.route("/api/easy", methods=["POST"])
def easy():
    json_data = request.get_json()
    try:
        image = json_data["image"]
    except Exception:
        raise Exception("Invalid Param")
    if not isinstance(image, str) or image == "":
        raise Exception("Invalid Param")
    image = Image.open(BytesIO(base64.b64decode(image)))
    texts = reader.readtext(image, detail=0)
    return jsonify({"texts": texts})