Spaces:
Running
Running
File size: 1,508 Bytes
5abbb8c b5c05cd 5abbb8c 8a2e49f b5c05cd 28d0c5f 74a35d9 5abbb8c 74a35d9 28d0c5f 5abbb8c 28d0c5f 7b1ddd7 3fdcb38 7b1ddd7 3fdcb38 28d0c5f b5c05cd 8a2e49f b5c05cd 8a2e49f |
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 |
import json
import os
import webbrowser
from aip_trainer import app_logger, log_level
from flask import Flask, render_template, request
from flask_cors import CORS
from aip_trainer.lambdas import lambdaGetSample
from aip_trainer.lambdas import lambdaSpeechToScore
app = Flask(__name__, template_folder="static")
cors = CORS(app)
app.config['CORS_HEADERS'] = '*'
rootPath = ''
@app.route(rootPath+'/')
def main():
return render_template('main.html')
@app.route(rootPath+'/getSample', methods=['POST'])
def getNext():
event = {'body': json.dumps(request.get_json(force=True))}
return lambdaGetSample.lambda_handler(event, [])
@app.route(rootPath+'/GetAccuracyFromRecordedAudio', methods=['POST'])
def GetAccuracyFromRecordedAudio():
try:
event = {'body': json.dumps(request.get_json(force=True))}
lambda_correct_output = lambdaSpeechToScore.lambda_handler(event, [])
return lambda_correct_output
except Exception as e:
import traceback
app_logger.error(e)
app_logger.error(traceback.format_exc())
raise e
if __name__ == "__main__":
is_docker_container = os.getenv("IS_DOCKER_CONTAINER", "").lower() == "yes"
app_logger.info(f"is_docker_container:{is_docker_container}.")
hostname = "127.0.0.1" if is_docker_container else "0.0.0.0"
if not is_docker_container:
import webbrowser
webbrowser.open_new('http://127.0.0.1:3000/')
app.run(host=hostname, port=3000, debug=log_level=="DEBUG")
|