-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
46 lines (37 loc) · 1.21 KB
/
main.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
46
from wsgiref import simple_server
from flask import Flask, request, jsonify
from flask import Response
import os
from flask_cors import CORS
from kerasa.predict2 import predict
from my_utilities.decode import decodeSound
os.putenv('LANG', 'en_US.UTF-8')
os.putenv('LC_ALL', 'en_US.UTF-8')
app = Flask(__name__)
CORS(app)
# This is different from clientApp because it doesn't have any frontend interface and it have code for exception error.
@app.route("/predict", methods=['POST'])
def predictRoute():
try:
image = request.json['sound']
decodeSound(image, "audio123.wav")
result = predict()
#print(result)
#print(type(result))
#return jsonify(result)
except ValueError as val:
print(val)
return Response("Value not found inside json data")
except KeyError:
return Response("Key value error incorrect key passed")
except Exception as e:
print(e)
result = "Invalid input"
return {"Result": result}
# port = int(os.getenv("PORT"))
if __name__ == "__main__":
host = '0.0.0.0'
port = 8000
httpd = simple_server.make_server(host, port, app)
print("Serving on %s %d" % (host, port))
httpd.serve_forever()