-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
68 lines (52 loc) · 2.24 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
#############################################################################################################################
# DETECTING CARDIOVASCULAR DISEASES USING MACHINE LEARNING AND ARTIFICIAL INTELLIGENCE #
# FYP BY MIAN INSHAULLAH, FAKEHA SAEED, SANA SIKANDAR, JAWERIA WAHEED #
# SUPERVISED BY DR. NASIR AHMED, ADVISED BY ENGR. NAINA SAID #
#############################################################################################################################
#LIBRARIES
#Machine Learning and Data Science Dependencies
import pickle
import sklearn
import numpy as np
import pandas as pd
import tensorflow as tf
from threading import Timer
from tensorflow.python.keras.models import save_model, load_model
#Web App Dependencies
import webbrowser
from flask import Flask, request, render_template
#Plotting Dependecies
import io
import random
from flask import Flask, Response, request
from matplotlib.backends.backend_agg import FigureCanvasAgg
from matplotlib.backends.backend_svg import FigureCanvasSVG
#Deployment of Machine Learing Model using Flask
app = Flask(__name__)
model = load_model('model.h5',compile=True)
name = ['Normal','Atrial Fibrillation','Ventricular Fibrillation','Right Bundle Branch Block','Left Bundle Branch Block']
def load(filename):
print(filename)
test = pd.read_csv(filename)
print(len(test))
#test = df.drop(columns=df.columns[360], axis=1)
test = test.iloc[:,:test.shape[1]-1].values
test = test.reshape(1,360,1)
return test
@app.route('/',methods=['GET'])
def hello_world():
return render_template('index.html')
@app.route('/',methods=['POST'])
def predict():
imagefile = request.files['imagefile']
print(imagefile)
imagepath = "" + imagefile.filename
data = load(imagepath)
print(data)
y_pred = model.predict(data)
return render_template('index.html',prediction=name[np.argmax(y_pred)])
def open_browser():
webbrowser.open_new('http://127.0.0.1:8080/')
if __name__ == "__main__":
Timer(1, open_browser).start()
app.run(port=8080)