nishantguvvada commited on
Commit
f104f32
1 Parent(s): ace842f

updated to working version

Browse files
Files changed (1) hide show
  1. app.py +31 -82
app.py CHANGED
@@ -1,94 +1,43 @@
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
- )
 
1
  import streamlit as st
2
  import tensorflow as tf
3
+ import cv2
4
+ import numpy as np
5
+ from PIL import Image, ImageOps
6
+ import imageio.v3 as iio
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ @st.cache_resource()
9
  def load_model():
10
+ model=tf.keras.models.load_model('./hip_impant_model.h5')
11
  return model
12
+
13
+ st.title(":blue[Nishant Guvvada's] :red[AI Journey] The Hip-Implant X-ray Assistant")
14
+ image = Image.open('./title.jpg')
15
+ st.image(image)
16
  st.write("""
17
  # Image Classification
18
  """
19
  )
20
 
21
+ file = st.file_uploader("Upload an X-ray image", type= ['png', 'jpg'])
22
+
23
+ def model_prediction(path):
24
+ resize = tf.image.resize(path, (256,256))
25
+ with st.spinner('Model is being loaded..'):
26
+ model=load_model()
 
27
  yhat = model.predict(np.expand_dims(resize/255, 0))
28
+ return yhat
29
+
30
+ def on_click():
31
+ if file is None:
32
+ st.text("Please upload an image file")
33
  else:
34
+ image = Image.open(file)
35
+ st.image(image, use_column_width=True)
36
+ image = image.convert('RGB')
37
+ predictions = model_prediction(np.array(image))
38
+ if (predictions>0.5):
39
+ st.write("""# Prediction : Implant is loose""")
40
+ else:
41
+ st.write("""# Prediction : Implant is in control""")
42
+
43
+ st.button('Predict', on_click=on_click)