-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
45 lines (31 loc) · 1.14 KB
/
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
36
37
38
39
40
41
42
43
44
45
import sys
from flask import Flask, request, jsonify
from flask_cors import CORS, cross_origin
import json
import base64
from ProductSuggestion import ProductSuggestion
import GCFunctions
GCFunctions.init_import()
app = Flask(__name__)
productSuggestion = ProductSuggestion()
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
@app.route('/data', methods=["GET"])
def check():
data = json.loads(request.get_data().decode('UTF-8'))
@app.route('/suggestions', methods=["GET", "POST"])
def product_suggestion():
data = request.get_data()
return productSuggestion.run(base64.decodebytes(data))
@app.route('/ocr', methods=["POST"])
def ocr():
print("ocr endpoint")
data = request.get_data()
return {"items":GCFunctions.productQuery("image binary", base64.decodebytes(data), 5)}
@app.route('/search', methods=["POST"])
def search():
data = json.loads(request.get_data().decode('UTF-8'))
return {"items": GCFunctions.productQuery("labels",data["text"].split(), 20)}
if __name__ == '__main__':
# Threaded option to enable multiple instances for multiple user access support
app.run(threaded=True, port=5000)