feat(ocr): use base64 image
Browse files- pdm.lock +1 -1
- pyproject.toml +1 -0
- src/app.py +4 -0
pdm.lock
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
groups = ["default"]
|
6 |
strategy = ["cross_platform", "inherit_metadata"]
|
7 |
lock_version = "4.4.1"
|
8 |
-
content_hash = "sha256:
|
9 |
|
10 |
[[package]]
|
11 |
name = "blinker"
|
|
|
5 |
groups = ["default"]
|
6 |
strategy = ["cross_platform", "inherit_metadata"]
|
7 |
lock_version = "4.4.1"
|
8 |
+
content_hash = "sha256:fee1e0513a319e49829a13033a3d4251f1164219227617d1603052f924221e65"
|
9 |
|
10 |
[[package]]
|
11 |
name = "blinker"
|
pyproject.toml
CHANGED
@@ -9,6 +9,7 @@ dependencies = [
|
|
9 |
"easyocr>=1.7.1",
|
10 |
"flask>=3.0.0",
|
11 |
"gunicorn>=21.2.0",
|
|
|
12 |
]
|
13 |
requires-python = ">=3.9"
|
14 |
readme = "README.md"
|
|
|
9 |
"easyocr>=1.7.1",
|
10 |
"flask>=3.0.0",
|
11 |
"gunicorn>=21.2.0",
|
12 |
+
"pillow>=10.1.0",
|
13 |
]
|
14 |
requires-python = ">=3.9"
|
15 |
readme = "README.md"
|
src/app.py
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
import easyocr
|
|
|
|
|
|
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
|
@@ -20,5 +23,6 @@ def easy():
|
|
20 |
raise Exception("Invalid Param")
|
21 |
if not isinstance(image, str) or image == "":
|
22 |
raise Exception("Invalid Param")
|
|
|
23 |
texts = reader.readtext(image, detail=0)
|
24 |
return jsonify({"texts": texts})
|
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
import easyocr
|
3 |
+
from PIL import Image
|
4 |
+
import base64
|
5 |
+
from io import BytesIO
|
6 |
|
7 |
app = Flask(__name__)
|
8 |
|
|
|
23 |
raise Exception("Invalid Param")
|
24 |
if not isinstance(image, str) or image == "":
|
25 |
raise Exception("Invalid Param")
|
26 |
+
image = Image.open(BytesIO(base64.b64decode(image)))
|
27 |
texts = reader.readtext(image, detail=0)
|
28 |
return jsonify({"texts": texts})
|