Spaces:
Sleeping
Sleeping
import streamlit as st | |
import tensorflow as tf | |
from PIL import Image | |
from src.utils import * | |
from src.vertex import * | |
st.set_page_config( | |
page_title="Hip-Implant Image Classification", | |
page_icon=":robot:", | |
layout="centered", | |
initial_sidebar_state="expanded", | |
menu_items={ | |
'How to use': "# Upload an image of a hip-implant (search <loose hip implant> on google), the app will classify the hip-implant as loose or in-control." | |
} | |
) | |
#creating session states | |
create_session_state() | |
image = Image.open('./image/title.jpg') | |
st.image(image) | |
st.title(":red[My AI Journey] :blue[Nishant Guvvada] X-ray Assistant") | |
with st.sidebar: | |
image = Image.open('./image/sidebar_image.jpg') | |
st.image(image) | |
st.markdown("<h2 style='text-align: center; color: red;'>Settings Tab</h2>", unsafe_allow_html=True) | |
st.write("Model Settings:") | |
#define the temeperature for the model | |
temperature_value = st.slider('Temperature :', 0.0, 1.0, 0.2) | |
st.session_state['temperature'] = temperature_value | |
#define the temeperature for the model | |
token_limit_value = st.slider('Token limit :', 1, 1024, 256) | |
st.session_state['token_limit'] = token_limit_value | |
#define the temeperature for the model | |
top_k_value = st.slider('Top-K :', 1,40,40) | |
st.session_state['top_k'] = top_k_value | |
#define the temeperature for the model | |
top_p_value = st.slider('Top-P :', 0.0, 1.0, 0.8) | |
st.session_state['top_p'] = top_p_value | |
if st.button("Reset Session"): | |
reset_session() | |
st.image(bytes_data, caption='User uploaded image') | |
st.balloons() | |
def load_model(): | |
model=tf.keras.models.load_model('/Hip-Implant/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") | |
import cv2 | |
from PIL import Image, ImageOps | |
import numpy as np | |
st.set_option('deprecation.showfileUploaderEncoding', False) | |
def model_prediction(img, model): | |
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 | |
if file is None: | |
st.text("Please upload an image file") | |
else: | |
image = Image.open(file) | |
st.image(image, use_column_width=True) | |
predictions = mode_prediction(image, model) | |
st.write(prediction) | |
print( | |
"This image most likely belongs to {}." | |
.format(prediction) | |
) | |