Commit 43551a5a authored by Lihinikaduwa D.N.R.  's avatar Lihinikaduwa D.N.R.

Merge branch 'it18257632' into 'master'

It18257632

See merge request !136
parents 9b5c972a 28fd5f36
...@@ -6,7 +6,10 @@ ...@@ -6,7 +6,10 @@
<excludeFolder url="file://$MODULE_DIR$/API/venv" /> <excludeFolder url="file://$MODULE_DIR$/API/venv" />
<excludeFolder url="file://$MODULE_DIR$/backend/IT18257632/venv" /> <excludeFolder url="file://$MODULE_DIR$/backend/IT18257632/venv" />
</content> </content>
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Python 3.8" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
<component name="PyDocumentationSettings">
<option name="renderExternalDocumentation" value="true" />
</component>
</module> </module>
\ No newline at end of file
...@@ -9,5 +9,12 @@ ...@@ -9,5 +9,12 @@
</list> </list>
</option> </option>
</inspection_tool> </inspection_tool>
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="tensorflow.keras" />
</list>
</option>
</inspection_tool>
</profile> </profile>
</component> </component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
</project> </project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PySciProjectComponent">
<option name="PY_SCI_VIEW" value="true" />
<option name="PY_SCI_VIEW_SUGGESTED" value="true" />
</component>
</project>
\ No newline at end of file
No preview for this file type
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="Flask">
<option name="enabled" value="true" />
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">
<option name="TEMPLATE_CONFIGURATION" value="Jinja2" />
<option name="TEMPLATE_FOLDERS">
<list>
<option value="$MODULE_DIR$/templates" />
</list>
</option>
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/API.iml" filepath="$PROJECT_DIR$/.idea/API.iml" />
</modules>
</component>
</project>
\ No newline at end of file
...@@ -3,8 +3,13 @@ import random ...@@ -3,8 +3,13 @@ import random
import os import os
from API.model.colorModel import get_color_activities1, get_color_activities2, get_color_activity_result from API.model.colorModel import get_color_activities1, get_color_activities2, get_color_activity_result
from API.model.readModel import get_reading_activities from API.model.readModel import get_reading_activities
from API.model.userModel import getStudentByName
from API.routers.router import funtion_one from API.routers.router import funtion_one
from backend.IT18218640.keyword_spotting_service import Keyword_Spotting_service # from backend.IT18218640.keyword_spotting_service import Keyword_Spotting_service
# from flask_mysqldb import MySQL
# import MySQLdb.cursors
# import re
app = Flask(__name__) app = Flask(__name__)
...@@ -14,6 +19,31 @@ app = Flask(__name__) ...@@ -14,6 +19,31 @@ app = Flask(__name__)
def home(): def home():
return render_template('home.html') return render_template('home.html')
# @app.route('/register', methods =['POST'])
# def register():
# msg = ''
# if request.method == 'POST' and 'username' in request.form and 'password' in request.form and 'email' in request.form:
# username = request.form['username']
# password = request.form['password']
# email = request.form['email']
# cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
# cursor.execute('SELECT * FROM user WHERE name = % s', (username,))
# account = cursor.fetchone()
# if account:
# msg = 'Account already exists !'
# elif not re.match(r'[^@]+@[^@]+\.[^@]+', email):
# msg = 'Invalid email address !'
# elif not re.match(r'[A-Za-z0-9]+', username):
# msg = 'Username must contain only characters and numbers !'
# elif not username or not password or not email:
# msg = 'Please fill out the form !'
# else:
# cursor.execute('INSERT INTO accounts VALUES (NULL, % s, % s, % s)', (username, password, email,))
# mysql.connection.commit()
# msg = 'You have successfully registered !'
# elif request.method == 'POST':
# msg = 'Please fill out the form !'
# return msg
# Color Function Route (IT18218640) # Color Function Route (IT18218640)
@app.route("/getColorActivities1") @app.route("/getColorActivities1")
...@@ -29,43 +59,43 @@ def getColorActivitiesResult(): ...@@ -29,43 +59,43 @@ def getColorActivitiesResult():
# print("data_dic") # print("data_dic")
return get_color_activity_result() return get_color_activity_result()
@app.route("/predict", methods=["POST"]) # @app.route("/predict", methods=["POST"])
def predict(): # def predict():
# get audio file and save it # # get audio file and save it
audio_file = request.files["file"] # audio_file = request.files["file"]
#
print(f"{request.files['file']}") # print(f"{request.files['file']}")
# print(f"{request.files['name']}") # # print(f"{request.files['name']}")
#
###################################### # ######################################
print(f"{request.form['name']}") # print(f"{request.form['name']}")
##################################### # #####################################
# print(f"{request.json}") # # print(f"{request.json}")
#
file_name = str(random.randint(0, 100000)) # file_name = str(random.randint(0, 100000))
# audio_file.save((file_name)) # # audio_file.save((file_name))
#
# get file name # # get file name
# predict_file_name = audio_file.filename # # predict_file_name = audio_file.filename
# predict_file_name = predict_file_name.split("/") # # predict_file_name = predict_file_name.split("/")
# new_predict_file_name = predict_file_name[1] # # new_predict_file_name = predict_file_name[1]
# new_predict_file_name = new_predict_file_name.split(".") # # new_predict_file_name = new_predict_file_name.split(".")
# FPFN = new_predict_file_name[0] # # FPFN = new_predict_file_name[0]
# print(f"{FPFN}") # # print(f"{FPFN}")
#
# invoke keyword spotting service # # invoke keyword spotting service
kss = Keyword_Spotting_service() # kss = Keyword_Spotting_service()
#
# make a prediction # # make a prediction
predicted_keyword = kss.predict(file_name, request.form['name']) # predicted_keyword = kss.predict(file_name, request.form['name'])
#
# remove the audio file # # remove the audio file
os.remove(file_name) # os.remove(file_name)
#
# send back the predicted keword in json format # # send back the predicted keword in json format
data = {"Keyword": predicted_keyword} # data = {"Keyword": predicted_keyword}
return jsonify(data) # return jsonify(data)
# return "audio_file" # # return "audio_file"
# Read Function Route (IT) # Read Function Route (IT)
...@@ -91,9 +121,29 @@ def abc(): ...@@ -91,9 +121,29 @@ def abc():
# return make_response(d, 200) # return make_response(d, 200)
return response_val return response_val
# Loging
@app.route("/login", methods=['POST'])
def login():
req = request.get_json()
username = req['username']
password = req['password']
user = getStudentByName(username, password)
if len(user) == 0:
data = {
"body": [],
"message": "Failed"
}
else:
data = {
"body": user,
"message": "Success"
}
body = jsonify(data)
return make_response(body)
if __name__ == "__main__": if __name__ == "__main__":
app.run(host='192.168.8.101') # app.run(host='192.168.8.101')
# app.run(host='192.168.8.100,port='5000', debug=True) # app.run(host='192.168.8.100,port='5000', debug=True)
# app.run(debug=True) app.run(debug=True)
...@@ -12,13 +12,13 @@ def create_con(): ...@@ -12,13 +12,13 @@ def create_con():
database="helply", database="helply",
host="127.0.0.1", host="127.0.0.1",
user="root", user="root",
password="rp19970520" password="12345678"
) )
return db return db
def create_con_pandas(): def create_con_pandas():
db_connection_str = 'mysql+mysqlconnector://root:rp19970520@127.0.0.1/helply' db_connection_str = 'mysql+mysqlconnector://root:12345678@127.0.0.1/helply'
db = create_engine(db_connection_str) db = create_engine(db_connection_str)
return db return db
......
from API.db.dbConnection import get_data
def getStudentByName(username, password):
qry = 'SELECT * FROM `user` WHERE name = "{}" AND password = "{}"'.format(username, password)
user = get_data(qry)
return user
{
"mappings": [],
"labels": [],
"MFCCs": [],
"files": []
}
\ 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