MiklX commited on
Commit
00d1ad6
·
1 Parent(s): 54daddb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -18
app.py CHANGED
@@ -1,21 +1,16 @@
1
- import cv2
2
- import pytesseract
3
- from pytesseract import Output
4
- from flask import Flask, render_template_string
 
5
  app = Flask(__name__)
6
- @app.route('/')
7
- def home():
8
- image_path = 'https://prezentacii.org/upload/cloud/19/01/118181/images/screen7.jpg'
9
- image = cv2.imread(image_path)
10
- d = pytesseract.image_to_data(image, output_type=Output.DICT)
11
- html = '<div style="position: relative;">'
12
- html += f'<img src="{{ url_for("static", filename="{image_path}") }}" alt="image">'
13
- n_boxes = len(d['text'])
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)