|
import os |
|
import tempfile |
|
import numpy as np |
|
import streamlit as st |
|
import tensorflow as tf |
|
from PIL import Image |
|
from tensorflow.keras.preprocessing.image import load_img, img_to_array |
|
|
|
|
|
st.title("Nova'23 Classification Model Playground!") |
|
st.write("Upload the x-ray image") |
|
|
|
uploaded_file = st.file_uploader('Upload an image', type=['jpg', 'jpeg', 'png']) |
|
if uploaded_file is not None: |
|
|
|
with tempfile.NamedTemporaryFile(delete=False) as f: |
|
f.write(uploaded_file.read()) |
|
|
|
|
|
img_path = f.name |
|
|
|
|
|
image = Image.open(uploaded_file) |
|
st.image(image, caption='Uploaded Image', use_column_width=True) |
|
|
|
|
|
height = 180 |
|
width = 180 |
|
channels = 3 |
|
img = load_img(img_path, target_size=(height, width)) |
|
img_array = img_to_array(img) |
|
img_array = img_array / 255.0 |
|
img_array = tf.reshape(img_array, [1, height, width, channels]) |
|
|
|
model = tf.keras.models.load_model('nova.h5') |
|
|
|
prediction = model.predict(img_array) |
|
|
|
if prediction[0][0] > 0.5: |
|
print("Prediction: Pneumonia") |
|
st.write("Prediction: Pneumonia") |
|
else: |
|
print("Prediction: Normal") |
|
st.write("Prediction: Normal") |
|
|
|
os.remove(img_path) |
|
|