Commit 383cab84 authored by W.D.R.P. Sandeepa's avatar W.D.R.P. Sandeepa

Merge branch 'it18218640' into 'master'

change route

See merge request !123
parents 7f09f8f5 3c577846
from flask import Flask, redirect, url_for, render_template, request, jsonify, make_response
import random
import os
from API.model.colorModel import get_color_activities, get_color_activity_result
from API.model.readModel import get_reading_activities
from API.routers.router import funtion_one
from backend.IT18218640.keyword_spotting_service import Keyword_Spotting_service
app = Flask(__name__)
......@@ -23,6 +25,43 @@ def getColorActivitiesResult():
# print("data_dic")
return get_color_activity_result()
@app.route("/predict", methods=["POST"])
def predict():
# get audio file and save it
audio_file = request.files["file"]
print(f"{request.files['file']}")
# print(f"{request.files['name']}")
######################################
print(f"{request.form['name']}")
#####################################
# print(f"{request.json}")
file_name = str(random.randint(0, 100000))
# audio_file.save((file_name))
# get file name
# predict_file_name = audio_file.filename
# predict_file_name = predict_file_name.split("/")
# new_predict_file_name = predict_file_name[1]
# new_predict_file_name = new_predict_file_name.split(".")
# FPFN = new_predict_file_name[0]
# print(f"{FPFN}")
# invoke keyword spotting service
kss = Keyword_Spotting_service()
# make a prediction
predicted_keyword = kss.predict(file_name, request.form['name'])
# remove the audio file
os.remove(file_name)
# send back the predicted keword in json format
data = {"Keyword": predicted_keyword}
return jsonify(data)
# return "audio_file"
# Read Function Route (IT)
......
import requests
URL = "http://192.168.8.101:5000/predict"
URL = "http://192.168.8.100:5000/predict"
TEST_AUDIO_FILE_PATH = "test/red.wav"
if __name__ == "__main__":
......
......@@ -17,9 +17,11 @@ class _Keyword_Spotting_Service:
"yellow"
]
_instance = None
# 78293
def predict(self, file_path, FPFN):
print(f"{file_path}")
# extract MFCCs
MFCCs = self.preprocess(file_path) # (# segment, # coefficients)
......
......@@ -7,25 +7,26 @@ app = Flask(__name__)
@app.route("/predict", methods=["POST"])
def predict():
# get audio file and save it
audio_file = request.files["file"]
# print(f"{request.files['file']}")
# print(f"{request.files['name']}")
file_name = str(random.randint(0, 100000))
audio_file.save((file_name))
# get file name
predict_file_name = audio_file.filename
predict_file_name = predict_file_name.split("/")
new_predict_file_name = predict_file_name[1]
new_predict_file_name = new_predict_file_name.split(".")
FPFN = new_predict_file_name[0]
# predict_file_name = audio_file.filename
# predict_file_name = predict_file_name.split("/")
# new_predict_file_name = predict_file_name[1]
# new_predict_file_name = new_predict_file_name.split(".")
# FPFN = new_predict_file_name[0]
FPFN = request.form['name']
# print(f"{FPFN}")
# invoke keyword spotting service
kss = Keyword_Spotting_service()
# make a prediction
predicted_keyword = kss.predict(file_name, FPFN)
......@@ -33,10 +34,11 @@ def predict():
os.remove(file_name)
# send back the predicted keword in json format
data = {"Keyword": predicted_keyword}
data = {"Keyword" : predicted_keyword}
return jsonify(data)
if __name__ == "__main__":
app.run(host='192.168.8.101')
app.run(host='192.168.8.100')
#app.run(host='192.168.8.100,port='5000', debug=True)
# app.run(debug=False)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment