-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
105 lines (90 loc) · 3.26 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#import Flask Framework
from flask import *
from detect_cnn import *
from datetime import datetime
import sqlite3
import tensorflow.keras as keras
#Initialize Flask app
app = Flask(__name__)
#Root Route
@app.route('/')
def home():
return render_template('index.html')
#Login Route
@app.route('/login')
def login():
return render_template('login.html')
#Team Route
@app.route('/team')
def team():
return render_template('team.html')
#Contact Route
@app.route('/contact', methods=['POST','GET'])
def contact():
if 'message' in request.args:
message = request.args.get('message')
return render_template('contact.html', message=message)
return render_template('contact.html')
@app.route('/submitcontact', methods=['POST'])
def submit_contact():
if request.method == "POST":
name = request.form['name']
email = request.form['email']
message = request.form['message']
# datetime object containing current date and time
now = datetime.now()
# dd/mm/YY H:M:S
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
#Make a connection
myconnection = sqlite3.connect('soundlogy_database.db')
#Make a cursor which will perform certain actions
mycursor = myconnection.cursor()
#Execute Given action
mycursor.execute("INSERT INTO contact VALUES (:timestamp,:name,:email,:message)", {
'timestamp': dt_string, 'name': name, 'email': email, 'message': message})
#Take acknowledgement
myconnection.commit()
#Close Connection
myconnection.close()
return redirect(url_for('contact',message="Thank you for submitting your query! We will get back to you soon."))
@app.route('/detect', methods=['POST'])
def detect():
name = request.form['name']
#File Input
user_input = request.files['song']
#stuff you do with the file goes here
f_name = 'test/input/'+user_input.filename
uploadedIMG = os.path.join(f_name)
user_input.save(uploadedIMG)
# datetime object containing current date and time
now = datetime.now()
# dd/mm/YY H:M:S
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
genre = detect_genre_cnn()
#Make a connection
myconnection = sqlite3.connect('soundlogy_database.db')
#Make a cursor which will perform certain actions
mycursor = myconnection.cursor()
#Execute Given action
mycursor.execute("INSERT INTO detection VALUES (:timestamp,:name,:filename,:genre)", {
'timestamp': dt_string, 'name': name, 'filename': user_input.filename, 'genre': genre})
#Take acknowledgement
myconnection.commit()
#Close Connection
myconnection.close()
return render_template('detect.html', genre=genre)
@app.route('/summary')
def summary():
cnn_model = keras.models.load_model('saved_model/my_CNN_model')
rnn_model = keras.models.load_model('saved_model/my_RNN_model')
mlp_model = keras.models.load_model('saved_model/my_MLP_model')
print("\n\nCNN MODEL SUMMARY")
cnn_model.summary()
print("RNN MODEL SUMMARY")
rnn_model.summary()
print("MLP MODEL SUMMARY")
mlp_model.summary()
return render_template('summary.html')
#Run Flask app when the python file is ran
if __name__ == "__main__":
app.run(debug=True)