Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +42 -0
- model.h5 +3 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import numpy as np
|
4 |
+
import tensorflow as tf
|
5 |
+
from tensorflow.keras.preprocessing import image
|
6 |
+
|
7 |
+
# Function to preprocess the uploaded image
|
8 |
+
def preprocess_uploaded_image(uploaded_image, target_size):
|
9 |
+
img = Image.open(uploaded_image)
|
10 |
+
img = img.resize(target_size)
|
11 |
+
img_array = image.img_to_array(img)
|
12 |
+
img_array = np.expand_dims(img_array, axis=0)
|
13 |
+
return img_array
|
14 |
+
|
15 |
+
# Function to load the model and make predictions
|
16 |
+
def predict_image_class(model_path, uploaded_image, target_size):
|
17 |
+
loaded_model = tf.keras.models.load_model(model_path)
|
18 |
+
img = preprocess_uploaded_image(uploaded_image, target_size)
|
19 |
+
prediction = loaded_model.predict(img)
|
20 |
+
class_idx = np.argmax(prediction)
|
21 |
+
return class_idx
|
22 |
+
|
23 |
+
def main():
|
24 |
+
st.title("Heart Disease Image Classifier")
|
25 |
+
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
26 |
+
|
27 |
+
if uploaded_image is not None:
|
28 |
+
st.image(uploaded_image, caption="Uploaded Image", use_column_width=True)
|
29 |
+
st.write("")
|
30 |
+
with st.spinner("Classifying..."):
|
31 |
+
# Classify the uploaded image
|
32 |
+
class_idx = predict_image_class("model.h5", uploaded_image, target_size=(224, 224))
|
33 |
+
|
34 |
+
if class_idx == 0:
|
35 |
+
st.write("The patient doesn't have heart disease")
|
36 |
+
else:
|
37 |
+
st.write("The patient has heart disease")
|
38 |
+
|
39 |
+
|
40 |
+
# Run the Streamlit app
|
41 |
+
if __name__ == "__main__":
|
42 |
+
main()
|
model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3dd424537b91fcf72a6272ec4b4007e045a9076cd863f3c8dbea448caf72e222
|
3 |
+
size 777579104
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pillow
|
3 |
+
numpy
|
4 |
+
tensorflow
|