Hip-Implant / app.py
nishantguvvada's picture
added button
8904fa3
raw
history blame
1.45 kB
import streamlit as st
import tensorflow as tf
import cv2
import numpy as np
from PIL import Image, ImageOps
#from io import BytesIO
@st.cache_resource()
def load_model():
model=tf.keras.models.load_model('./hip_impant_model.h5')
return model
with st.spinner('Model is being loaded..'):
model=load_model()
st.write("""
# Image Classification
"""
)
file = st.file_uploader("Upload an X-ray image", type= ['png', 'jpg'])
def model_prediction(image, model):
resize = tf.image.resize(image, (256,256))
yhat = model.predict(np.expand_dims(resize/255, 0))
if(yhat>0.5):
result = "Prediction is loose"
else:
result = "Prediction is control"
return result
def model_prediction(image, model):
img = cv2.imread(image)
plt.imshow(img)
plt.show()
resize = tf.image.resize(img, (256,256))
yhat = model.predict(np.expand_dims(resize/255, 0))
if(yhat>0.5):
result = "Prediction is loose"
else:
result = "Prediction is control"
return result
def on_click():
if file is None:
st.text("Please upload an image file")
else:
image = Image.open(file)
st.image(image, use_column_width=True)
predictions = model_prediction(image, model)
st.write(prediction)
print(
"This image most likely belongs to {}."
.format(prediction)
)
st.button('Predict', on_click=on_click)