import os
import numpy as np
from flask import Flask, request, render_template
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
app = Flask(__name__)
# Load trained model
MODEL_PATH =
'C:/Users/leesm/Downloads/SI-GuidedProject-78335-1656736746-main/flask/ECG.h5'
model = load_model(MODEL_PATH)
# Class labels
LABELS = ['Left Bundle Branch Block', 'Normal', 'Premature Atrial Contraction',
'Premature Ventricular Contractions', 'Right Bundle Branch Block',
'Ventricular Fibrillation']
@app.route("/") # Home page
def home():
return render_template("home.html")
@app.route("/about")
def about():
return render_template("home.html")
@app.route("/info")
def information():
return render_template("information.html")
@app.route("/upload", methods=["GET", "POST"])
def upload():
if request.method == "POST":
if "file" not in request.files or request.files["file"].filename == "":
return render_template("predict.html", error="No file uploaded.")
f = request.files["file"]
filename = f.filename # Get uploaded file name
filepath = os.path.join("uploads", filename)
os.makedirs("uploads", exist_ok=True) # Ensure directory exists
f.save(filepath)
# Load and preprocess the image
img = image.load_img(filepath, target_size=(64, 64))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
# Make prediction
pred = model.predict(x)
result = LABELS[np.argmax(pred)] # Get predicted class
return render_template("predict.html", prediction=result,
filename=filename)
return render_template("predict.html")
if __name__ == "__main__":
app.run(debug=True)