Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import tensorflow as tf
|
5 |
+
from tensorflow.keras.applications.resnet50 import preprocess_input
|
6 |
+
from tensorflow.keras.preprocessing.image import load_img, img_to_array
|
7 |
+
|
8 |
+
# Header
|
9 |
+
st.header('X-ray Chest Syptoms Classification')
|
10 |
+
|
11 |
+
# Input user
|
12 |
+
image_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
13 |
+
|
14 |
+
if image_file is not None:
|
15 |
+
# Preprocess input image
|
16 |
+
def preprocess_image(image_file):
|
17 |
+
image = load_img(image_file, target_size=(224, 224))
|
18 |
+
image = img_to_array(image)
|
19 |
+
image = preprocess_input(image)
|
20 |
+
image = np.expand_dims(image, axis=0)
|
21 |
+
return image
|
22 |
+
|
23 |
+
preprocessed_image = preprocess_image(image_file)
|
24 |
+
|
25 |
+
# Load model
|
26 |
+
model = tf.keras.models.load_model('./model.hdf5')
|
27 |
+
|
28 |
+
if preprocessed_image is not None:
|
29 |
+
# Make prediction
|
30 |
+
prediction = model.predict(preprocessed_image)
|
31 |
+
predicted_class = np.argmax(prediction)
|
32 |
+
class_labels = ['COVID19', 'NORMAL', 'PNEUMONIA', 'TURBERCULOSIS']
|
33 |
+
# Display the prediction
|
34 |
+
st.subheader("Prediction:")
|
35 |
+
st.write(f"Predicted Class: {class_labels[predicted_class]}")
|
36 |
+
st.write(f"Confidence: {prediction[0][predicted_class]:.2f}")
|