ilhamstoked commited on
Commit
424debf
1 Parent(s): f793624

Rename app1.py to app.py

Browse files
Files changed (1) hide show
  1. app1.py → app.py +20 -6
app1.py → app.py RENAMED
@@ -1,10 +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='35.201.127.49', port=443)
8
  #35.201.127.49:443
9
  #192.168.18.6:8501
10
 
@@ -31,11 +32,17 @@ def classify_image(image):
31
 
32
  # Run inference
33
  with st.spinner('Classifying...'):
 
34
  interpreter.invoke()
 
 
 
 
35
 
36
  # Get the output probabilities
37
  output_data = interpreter.get_tensor(output_details[0]['index'])
38
- return output_data[0]
 
39
 
40
  # Define the labels for the 7 classes
41
  labels = ['akiec', 'bcc', 'bkl', 'df', 'mel', 'nv', 'vasc']
@@ -61,24 +68,31 @@ def main():
61
  st.write("- ['mel'](https://en.wikipedia.org/wiki/Melanoma) - melanoma,")
62
  st.write("- ['vasc'](https://en.wikipedia.org/wiki/Vascular_anomaly) - vascular skin (Cherry Angiomas, Angiokeratomas, Pyogenic Granulomas.)")
63
  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. ")
64
- st.write(latency[0])
65
 
66
  # Get the input image from the user
67
  image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
68
 
69
  # Show the input image
70
  if image is not None:
71
- image = np.array(Image.open(image))
72
  st.image(image, width=150)
73
 
74
  # Run inference on the input image
75
- probs = classify_image(image)
 
 
 
76
 
77
  # Display the top 3 predictions
78
  top_3_indices = np.argsort(probs)[::-1][:3]
79
  st.write("Top 3 predictions:")
80
  for i in range(3):
81
  st.write("%d. %s (%.2f%%)" % (i + 1, labels[top_3_indices[i]], probs[top_3_indices[i]] * 100))
 
 
 
 
82
 
83
  if __name__ == '__main__':
84
- 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()