File size: 1,307 Bytes
4673d94 4f1bbae 4673d94 4f1bbae 4673d94 4f1bbae 4673d94 4f1bbae 4673d94 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
#import library
import pandas as pd
import numpy as np
import streamlit as st
from tensorflow.keras.preprocessing.image import load_img, img_to_array
import matplotlib.pyplot as plt
from PIL import Image
import tensorflow as tf
from tensorflow.keras.models import load_model
import tensorflow_hub as hub
#import pickle
import pickle
#load model
def run():
file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
model = load_model('model_tl.h5', custom_objects={'KerasLayer': hub.KerasLayer})
target_size=(224, 224)
def import_and_predict(image_data, model):
image = tf.keras.utils.load_img(image_data, target_size=(224, 224))
x = tf.keras.utils.img_to_array(image)
x = np.expand_dims(x, axis=0)
plt.imshow(image)
plt.axis('off')
plt.show()
# Make prediction
classes = model.predict(x)
result_pred = np.where(classes < 0.7, 0, 1)
if result_pred == 1:
result = 'Pneumonia'
else:
result = 'Normal'
return f"Prediction: {result}"
if file is None:
st.text("Please upload an image file")
else:
result = import_and_predict(file, model)
st.image(file)
st.write(result)
if __name__ == "__main__":
run() |