Spaces:
Sleeping
Sleeping
nishantguvvada
commited on
Commit
·
3982870
1
Parent(s):
15fa87e
upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import tensorflow as tf
|
3 |
+
from PIL import Image
|
4 |
+
from src.utils import *
|
5 |
+
from src.vertex import *
|
6 |
+
|
7 |
+
st.set_page_config(
|
8 |
+
page_title="Hip-Implant Image Classification",
|
9 |
+
page_icon=":robot:",
|
10 |
+
layout="centered",
|
11 |
+
initial_sidebar_state="expanded",
|
12 |
+
menu_items={
|
13 |
+
'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."
|
14 |
+
}
|
15 |
+
)
|
16 |
+
|
17 |
+
#creating session states
|
18 |
+
create_session_state()
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
image = Image.open('./image/title.jpg')
|
23 |
+
st.image(image)
|
24 |
+
st.title(":red[My AI Journey] :blue[Nishant Guvvada] X-ray Assistant")
|
25 |
+
|
26 |
+
with st.sidebar:
|
27 |
+
image = Image.open('./image/sidebar_image.jpg')
|
28 |
+
st.image(image)
|
29 |
+
st.markdown("<h2 style='text-align: center; color: red;'>Settings Tab</h2>", unsafe_allow_html=True)
|
30 |
+
|
31 |
+
|
32 |
+
st.write("Model Settings:")
|
33 |
+
|
34 |
+
#define the temeperature for the model
|
35 |
+
temperature_value = st.slider('Temperature :', 0.0, 1.0, 0.2)
|
36 |
+
st.session_state['temperature'] = temperature_value
|
37 |
+
|
38 |
+
#define the temeperature for the model
|
39 |
+
token_limit_value = st.slider('Token limit :', 1, 1024, 256)
|
40 |
+
st.session_state['token_limit'] = token_limit_value
|
41 |
+
|
42 |
+
#define the temeperature for the model
|
43 |
+
top_k_value = st.slider('Top-K :', 1,40,40)
|
44 |
+
st.session_state['top_k'] = top_k_value
|
45 |
+
|
46 |
+
#define the temeperature for the model
|
47 |
+
top_p_value = st.slider('Top-P :', 0.0, 1.0, 0.8)
|
48 |
+
st.session_state['top_p'] = top_p_value
|
49 |
+
|
50 |
+
if st.button("Reset Session"):
|
51 |
+
reset_session()
|
52 |
+
|
53 |
+
|
54 |
+
st.image(bytes_data, caption='User uploaded image')
|
55 |
+
st.balloons()
|
56 |
+
|
57 |
+
|
58 |
+
@st.cache(allow_output_mutation=True)
|
59 |
+
def load_model():
|
60 |
+
model=tf.keras.models.load_model('/Hip-Implant/hip_impant_model.h5')
|
61 |
+
return model
|
62 |
+
with st.spinner('Model is being loaded..'):
|
63 |
+
model=load_model()
|
64 |
+
|
65 |
+
st.write("""
|
66 |
+
# Image Classification
|
67 |
+
"""
|
68 |
+
)
|
69 |
+
|
70 |
+
file = st.file_uploader("Upload an X-ray image")
|
71 |
+
import cv2
|
72 |
+
from PIL import Image, ImageOps
|
73 |
+
import numpy as np
|
74 |
+
st.set_option('deprecation.showfileUploaderEncoding', False)
|
75 |
+
def model_prediction(img, model):
|
76 |
+
resize = tf.image.resize(img, (256,256))
|
77 |
+
yhat = model.predict(np.expand_dims(resize/255, 0))
|
78 |
+
if(yhat>0.5):
|
79 |
+
result = "Prediction is loose"
|
80 |
+
else:
|
81 |
+
result = "Prediction is control"
|
82 |
+
return result
|
83 |
+
|
84 |
+
if file is None:
|
85 |
+
st.text("Please upload an image file")
|
86 |
+
else:
|
87 |
+
image = Image.open(file)
|
88 |
+
st.image(image, use_column_width=True)
|
89 |
+
predictions = mode_prediction(image, model)
|
90 |
+
st.write(prediction)
|
91 |
+
print(
|
92 |
+
"This image most likely belongs to {}."
|
93 |
+
.format(prediction)
|
94 |
+
)
|