-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.py
40 lines (31 loc) · 1018 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
36
37
38
39
from flask import Flask, render_template, request
from celery.result import AsyncResult
from predict import papp
from predict import predict as cpredict
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/api/predict",methods=["POST"])
def predict():
print(request.json)
data = request.json.get("input-data")
task = cpredict.delay(data)
return {"status":"working","result-id":task.id}
@app.route("/api/get-result")
@app.route("/api/get-result/<taskid>")
def get_result(taskid: str = None):
if taskid is None:
return {"status":"error",
"message":"No taskid supplied"}
try:
task = AsyncResult(taskid,app=papp)
except Exception as e:
return {"status":"error","error":str(e)}
if task.state != "SUCCESS":
return {"status":task.state}
return {"status":task.state,"result":task.get()}
if __name__ == "__main__":
HOST = "0.0.0.0"
PORT = 5000
app.run(HOST,PORT,debug=True)