ilhamstoked commited on
Commit
960ce87
1 Parent(s): 89caba1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -1,11 +1,11 @@
1
  import streamlit as st
2
  import numpy as np
3
  import tensorflow as tf
 
4
  from tcp_latency import measure_latency
5
 
6
  # Measure Latency
7
- latency = measure_latency(host='34.203.133.210', port=443)
8
- #34.202.121.154:443
9
  #35.201.127.49:443
10
  #192.168.18.6:8501
11
 
@@ -32,11 +32,17 @@ def classify_image(image):
32
 
33
  # Run inference
34
  with st.spinner('Classifying...'):
 
35
  interpreter.invoke()
 
 
 
 
36
 
37
  # Get the output probabilities
38
  output_data = interpreter.get_tensor(output_details[0]['index'])
39
- return output_data[0]
 
40
 
41
  # Define the labels for the 7 classes
42
  labels = ['akiec', 'bcc', 'bkl', 'df', 'mel', 'nv', 'vasc']
@@ -62,24 +68,31 @@ def main():
62
  st.write("- ['mel'](https://en.wikipedia.org/wiki/Melanoma) - melanoma,")
63
  st.write("- ['vasc'](https://en.wikipedia.org/wiki/Vascular_anomaly) - vascular skin (Cherry Angiomas, Angiokeratomas, Pyogenic Granulomas.)")
64
  st.write("Due to imperfection of the model and a room of improvement for the future, if the probabilities shown are less than 70%, the skin is either healthy or the input image is unclear. This means that the model can be the first diagnostic of your skin illness. As precautions for your skin illness, it is better to do consultation with dermatologist. ")
65
- st.write(latency[0])
66
 
67
  # Get the input image from the user
68
  image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
69
 
70
  # Show the input image
71
  if image is not None:
72
- image = np.array(Image.open(image))
73
  st.image(image, width=150)
74
 
75
  # Run inference on the input image
76
- probs = classify_image(image)
 
 
 
77
 
78
  # Display the top 3 predictions
79
  top_3_indices = np.argsort(probs)[::-1][:3]
80
  st.write("Top 3 predictions:")
81
  for i in range(3):
82
  st.write("%d. %s (%.2f%%)" % (i + 1, labels[top_3_indices[i]], probs[top_3_indices[i]] * 100))
 
 
 
 
83
 
84
  if __name__ == '__main__':
85
- main()
 
1
  import streamlit as st
2
  import numpy as np
3
  import tensorflow as tf
4
+ import time
5
  from tcp_latency import measure_latency
6
 
7
  # Measure Latency
8
+
 
9
  #35.201.127.49:443
10
  #192.168.18.6:8501
11
 
 
32
 
33
  # Run inference
34
  with st.spinner('Classifying...'):
35
+ start_time = time.time()
36
  interpreter.invoke()
37
+ end_time = time.time()
38
+
39
+ # Calculate the classification duration
40
+ classifying_duration = end_time - start_time
41
 
42
  # Get the output probabilities
43
  output_data = interpreter.get_tensor(output_details[0]['index'])
44
+
45
+ return output_data[0], classifying_duration
46
 
47
  # Define the labels for the 7 classes
48
  labels = ['akiec', 'bcc', 'bkl', 'df', 'mel', 'nv', 'vasc']
 
68
  st.write("- ['mel'](https://en.wikipedia.org/wiki/Melanoma) - melanoma,")
69
  st.write("- ['vasc'](https://en.wikipedia.org/wiki/Vascular_anomaly) - vascular skin (Cherry Angiomas, Angiokeratomas, Pyogenic Granulomas.)")
70
  st.write("Due to imperfection of the model and a room of improvement for the future, if the probabilities shown are less than 70%, the skin is either healthy or the input image is unclear. This means that the model can be the first diagnostic of your skin illness. As precautions for your skin illness, it is better to do consultation with dermatologist. ")
71
+
72
 
73
  # Get the input image from the user
74
  image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
75
 
76
  # Show the input image
77
  if image is not None:
78
+ image = np.array(Image.open(image).convert("RGB"))
79
  st.image(image, width=150)
80
 
81
  # Run inference on the input image
82
+ probs, classifying_duration = classify_image(image)
83
+
84
+ # Display the classification duration
85
+ st.write(f"Classification duration: {classifying_duration:.4f} seconds")
86
 
87
  # Display the top 3 predictions
88
  top_3_indices = np.argsort(probs)[::-1][:3]
89
  st.write("Top 3 predictions:")
90
  for i in range(3):
91
  st.write("%d. %s (%.2f%%)" % (i + 1, labels[top_3_indices[i]], probs[top_3_indices[i]] * 100))
92
+
93
+ latency = measure_latency(host='35.201.127.49', port=443)
94
+ st.write("Network Latency:")
95
+ st.write(latency[0])
96
 
97
  if __name__ == '__main__':
98
+ main()