-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
59 lines (54 loc) · 1.37 KB
/
Copy pathapp.py
File metadata and controls
59 lines (54 loc) · 1.37 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from flask import Flask, request
from flask_cors import CORS
import redis
import json
import time
import uuid
r = redis.Redis(host='127.0.0.1', port=6379, db=0)
app = Flask(__name__,static_url_path='',static_folder="static/")
CORS(app)
@app.route("/")
def home():
return app.send_static_file("index.html")
@app.route("/gen-summary",methods=["POST"])
def run_summarize():
try:
sum_id = str(uuid.uuid4())
data = request.get_json()
r.set(f"job:{sum_id}", json.dumps({
"id": sum_id,
"time": time.time(),
"text":data["passage_input"],
"question":data["query_input"],
"response": "",
"isComplete":False
}))
return {
"error":False,
"id":sum_id
}
except Exception as error:
print(error)
return {
"error":True,
}
@app.route("/poll")
def poll():
try:
print(f"job:{request.args.get('id')}")
item = r.get(f"job:{request.args.get('id')}")
if item is None:
return {
"error":True,
"response":"error"
}
else:
return item
except Exception as error:
print(error)
return {
"error":True,
"response":"error"
}
if __name__ == '__main__':
app.run(debug=True)