yuripeyamashita's picture
Update app.py
2cf497b verified
raw
history blame
1.25 kB
from flask import Flask, request
from uuid import uuid4
import os, json
import requests
app = Flask(__name__)
secret = os.environ.get("auth")
headers = {'Authorization': os.environ.get("auth")}
res = {}
@app.route('/queue', methods=['POST'])
def queue():
if request.json.get('secret') != secret:
return {}, 400
uuid = str(uuid4())
res[uuid] = request.json
print(res[uuid])
return {'uuid': uuid}, 200
@app.route('/asr', methods=['GET'])
def asr():
uuid = request.args.get('uuid')
data = res.get(uuid)
if not data:
return {}, 400
print(data)
URL = data.get('URL')
body = data.get('body')
response = requests.post(URL, json=json.loads(body))
callbackURL = data.get('callbackURL')
requests.get(callbackURL)
return response.json()
# @app.route('/client', methods=['POST'])
# def client():
# token = request.json.get('token')
# data = reqList.get(token)
# if not data:
# return {}, 400
# print(data)
# URL = data.get('URL')
# postData = data.get('postData')
# response = requests.post(URL, json=postData)
# return response.json()
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860)