-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
35 lines (26 loc) · 864 Bytes
/
app.py
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
30
31
32
33
34
35
from flask import Flask, request, jsonify, render_template
from analyze import read_image
app = Flask(__name__, template_folder='templates')
@app.route("/")
def home():
return render_template('index.html')
# API at /api/v1/analysis/
@app.route("/api/v1/analysis/", methods=['GET'])
def analysis():
# Try to get the URI from the JSON
try:
get_json = request.get_json()
image_uri = get_json['uri']
except:
return jsonify({'error': 'Missing URI in JSON'}), 400
# Try to get the text from the image
try:
res = read_image(image_uri)
response_data = {
"text": res
}
return jsonify(response_data), 200
except:
return jsonify({'error': 'Error in processing'}), 500
if __name__ == "__main__":
app.run(host='0.0.0.0', port=3000, debug=True)