Download src/app.py from Hanchin/easy-ocr: direct link, hf CLI and curl.
- Browser
- Download file 656 Bytes
-
https://huggingface.co/spaces/Hanchin/easy-ocr/resolve/main/src/app.py
- Command line
-
hf download hf://spaces/Hanchin/easy-ocr/src/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Hanchin/easy-ocr/resolve/main/src/app.py
656 Bytes
| 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']) | |
| def index(): | |
| return "hello" | |
| 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}) | |