Upload 3 files
Browse files- .gitattributes +1 -0
- app.py +45 -0
- ecg_classification_model (1).keras +3 -0
- requirements.txt +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
ecg_classification_model[[:space:]](1).keras filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
import numpy as np
|
3 |
+
import gradio as gr
|
4 |
+
from tensorflow.keras.preprocessing import image
|
5 |
+
|
6 |
+
# Load the trained model
|
7 |
+
model = tf.keras.models.load_model("ecg_classification_model (1).keras", compile=False)
|
8 |
+
|
9 |
+
# Class labels (modify based on your dataset)
|
10 |
+
class_labels = [
|
11 |
+
"Left Bundle Branch Block",
|
12 |
+
"Normal",
|
13 |
+
"Premature Atrial Contraction",
|
14 |
+
"Premature Ventricular Contractions",
|
15 |
+
"Right Bundle Branch Block",
|
16 |
+
"Ventricular Fibrillation"
|
17 |
+
]
|
18 |
+
|
19 |
+
# Function to preprocess the image
|
20 |
+
def preprocess_image(img):
|
21 |
+
img = img.resize((224, 224)) # Resize to match model input
|
22 |
+
img_array = np.array(img) / 255.0 # Normalize
|
23 |
+
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
|
24 |
+
return img_array
|
25 |
+
|
26 |
+
# Function to make a prediction
|
27 |
+
def predict_ecg(img):
|
28 |
+
processed_img = preprocess_image(img)
|
29 |
+
prediction = model.predict(processed_img)
|
30 |
+
predicted_class = class_labels[np.argmax(prediction)]
|
31 |
+
return f"Predicted Class: {predicted_class}"
|
32 |
+
|
33 |
+
# Create Gradio Interface
|
34 |
+
iface = gr.Interface(
|
35 |
+
fn=predict_ecg,
|
36 |
+
inputs=gr.Image(type="pil"),
|
37 |
+
outputs="text",
|
38 |
+
title="ECG Image Classifier",
|
39 |
+
description="Upload an ECG image to classify it."
|
40 |
+
)
|
41 |
+
|
42 |
+
# Run the app
|
43 |
+
if __name__ == "__main__":
|
44 |
+
iface.launch(share=True)
|
45 |
+
|
ecg_classification_model (1).keras
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5692d3354588302d19b6938bc03ed12533a783dd125c1545787b55f16bac45d5
|
3 |
+
size 257015602
|
requirements.txt
ADDED
Binary file (74 Bytes). View file
|
|