0% found this document useful (0 votes)
7 views1 page

Code

This document is a Flask web application for predicting ECG classifications using a pre-trained model. It includes routes for the home page, about page, information page, and file upload for ECG image predictions. The application processes uploaded images, makes predictions using the model, and displays the results to the user.

Uploaded by

ilangoleshanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Code

This document is a Flask web application for predicting ECG classifications using a pre-trained model. It includes routes for the home page, about page, information page, and file upload for ECG image predictions. The application processes uploaded images, makes predictions using the model, and displays the results to the user.

Uploaded by

ilangoleshanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

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)

You might also like