Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,16 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
-
from
|
4 |
-
|
|
|
5 |
app = Flask(__name__)
|
6 |
-
@app.route('/')
|
7 |
-
def
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
for i in range(n_boxes):
|
15 |
-
if int(d['conf'][i]) > 60:
|
16 |
-
(x, y, w, h) = (d['left'][i], d['top'][i], d['width'][i], d['height'][i])
|
17 |
-
html += f'<div style="position: absolute; left: {x}px; top: {y}px;">{d["text"][i]}</div>'
|
18 |
-
html += '</div>'
|
19 |
-
return render_template_string(html)
|
20 |
if __name__ == '__main__':
|
21 |
app.run(host="0.0.0.0", port=7860, use_reloader=False)
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
import easyocr
|
3 |
+
from PIL import Image
|
4 |
+
import requests
|
5 |
+
from io import BytesIO
|
6 |
app = Flask(__name__)
|
7 |
+
@app.route('/read_image', methods=['POST'])
|
8 |
+
def read_image():
|
9 |
+
url = request.json['url']
|
10 |
+
response = requests.get(url)
|
11 |
+
image = Image.open(BytesIO(response.content))
|
12 |
+
reader = easyocr.Reader(['ru'], gpu=True)
|
13 |
+
text = reader.readtext(image)
|
14 |
+
return jsonify({'text': text})
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
if __name__ == '__main__':
|
16 |
app.run(host="0.0.0.0", port=7860, use_reloader=False)
|