-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
43 lines (31 loc) · 880 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
40
41
42
43
from pathlib import Path
from flask import Flask, request, send_file
from flask_cors import CORS
from flask_compress import Compress
# configuration
DEBUG = True
# instantiate the app
app = Flask(__name__)
app.config["SEND_FILE_MAX_AGE_DEFAULT"] = 0
Compress(app)
app.config.from_object(__name__)
IMAGE_ROOT = 'image'
# enable CORS
CORS(app, resources={r"/api/*": {"origins": "*"}})
@app.route("/api/text", methods=["GET"])
def get_text():
text = request.args.get("text")
res = {
"text": "I hear you, you say " + str(text)
}
return res
@app.route("/api/image", methods=["GET"])
def get_score():
name = request.args.get("name")
path = Path(IMAGE_ROOT) / name.split('/')[-1]
if path.is_file():
return send_file(path)
else:
return 'File not found.'
if __name__ == "__main__":
app.run(host="0.0.0.0", port=9000)