-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample
115 lines (75 loc) · 2.98 KB
/
sample
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
106
107
108
109
110
111
112
113
114
from flask import Flask, render_template, request, flash
app = Flask(__name__)
app.secret_key = "thomas"
@app.route('/')
def home():
return render_template('home.html')
@app.route('/login', methods=['POST','GET'])
def login():
return render_template('login.html')
check()
def check():
database = {'admin':'admin'}
uname=request.form['uname']
passw=request.form['pass']
if uname not in database :
return render_template('login.html',info='WRONG USERNAME OR PASSWORD')
else:
if database[uname] != passw:
return render_template('login.html',info='WRONG USERNAME OR PASSWORD')
else:
return render_template('prediction.html',info='WELCOME TO MUSIC CLASSIFIER')
@app.route('/prediction', methods=['POST','GET'])
def phome():
return render_template('prediction.html',info='WELCOME TO MUSIC CLASSIFIER')
def prediction():
aud = request.files['aud']
aud_path = "./images" + aud.filename
aud.save(aud_path)
return render_template('prediction.html',info='FILE IS UPLOADED')
if __name__ == '__main__':
app.run(debug=True)
from flask import Flask, render_template, request, flash
from cv2 import cv2
from librosa import librosa
from librosa import display
from numpy import numpy as np
from matplotlib import pyplot as plt
from tensorflow.keras.models import load_model
from sklearn.preprocessing import MinMaxScaler
app = Flask(__name__)
app.secret_key = "thomas"
model = load_model('imageclass.h5') # Replace with the actual path to your model
class_labels = ['Blue', 'Classical', 'Country', 'Disco', 'Hiphop', 'Jazz', 'Metal', 'Pop', 'Reggae', 'Rock']
@app.route('/')
def home():
return render_template('home.html')
@app.route('/login', methods=['POST', 'GET'])
def login():
return render_template('login.html')
@app.route('/check_login', methods=['POST'])
def check_login():
database = {'admin': 'admin'}
uname = request.form['uname']
passw = request.form['pass']
if uname not in database or database[uname] != passw:
return render_template('login.html', info='WRONG USERNAME OR PASSWORD')
return render_template('prediction.html', info='WELCOME TO MUSIC CLASSIFIER')
@app.route('/prediction', methods=['POST', 'GET'])
def phome():
return render_template('prediction.html', info='WELCOME TO MUSIC CLASSIFIER')
@app.route('/predict_music', methods=['POST'])
def predict_music():
aud = request.files['aud']
aud_path = "./images/" + aud.filename
aud.save(aud_path)
# Load the external audio file
y, sr = librosa.load(aud_path)
# ... (rest of your model prediction code)
# Make predictions using the loaded model
predictions = model.predict(np.expand_dims(spectrogram_resized, axis=0))
# Get the predicted label
predicted_label = class_labels[np.argmax(predictions)]
return render_template('prediction.html', info=f'Predicted Label: {predicted_label}')
if __name__ == '__main__':
app.run(debug=True)