iqbalpa's picture
Create app.py
ebffbc4
import streamlit as st
import pandas as pd
import numpy as np
import tensorflow as tf
from tensorflow.keras.applications.resnet50 import preprocess_input
from tensorflow.keras.preprocessing.image import load_img, img_to_array
# Header
st.header('X-ray Chest Syptoms Classification')
# Input user
image_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if image_file is not None:
# Preprocess input image
def preprocess_image(image_file):
image = load_img(image_file, target_size=(224, 224))
image = img_to_array(image)
image = preprocess_input(image)
image = np.expand_dims(image, axis=0)
return image
preprocessed_image = preprocess_image(image_file)
# Load model
model = tf.keras.models.load_model('./model.hdf5')
if preprocessed_image is not None:
# Make prediction
prediction = model.predict(preprocessed_image)
predicted_class = np.argmax(prediction)
class_labels = ['COVID19', 'NORMAL', 'PNEUMONIA', 'TURBERCULOSIS']
# Display the prediction
st.subheader("Prediction:")
st.write(f"Predicted Class: {class_labels[predicted_class]}")
st.write(f"Confidence: {prediction[0][predicted_class]:.2f}")