-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
48 lines (38 loc) · 1.43 KB
/
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
44
45
46
47
48
import os
from flask import Flask, jsonify, render_template, request
from flask_cors import CORS, cross_origin
from pydub import AudioSegment
from src.entity.config_entity import PredictionPipelineConfig
from src.pipe.prediction_pipeline import LanguageData, SinglePrediction
from src.pipe.training_pipeline import TrainingPipeline
from src.utils import decodesound
app = Flask(__name__)
CORS(app)
predictor = SinglePrediction(PredictionPipelineConfig())
@app.route('/', methods=['GET'])
@cross_origin()
def home():
return render_template('index.html')
@app.route("/train", methods=['GET'])
@cross_origin()
def train():
train_pipeline = TrainingPipeline()
train_pipeline.run_pipeline()
return jsonify(train_pipeline.get_result())
@app.route('/predict', methods=['POST'])
@cross_origin()
def predictroute():
config = PredictionPipelineConfig()
os.makedirs(config.prediction_artifact_dir, exist_ok=True)
input_sounds_path = config.input_sounds_path
app_artifacts = config.app_artifacts
os.makedirs(app_artifacts, exist_ok=True)
if request.method == 'POST':
base_64 = request.json['sound']
decodesound(base_64, input_sounds_path)
signal = LanguageData().load_data(wave_sounds_path)
signal.unsqueeze_(0)
result = predictor.predict_language(input_signal=signal)
return jsonify({"Result" : result})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080, debug=True)