Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -66,27 +66,55 @@ if uploaded_file is not None:
|
|
66 |
|
67 |
# class_indices = np.where(preds[0] > threshold)[0]
|
68 |
# class_probabilities = preds[0][class_indices]
|
69 |
-
class_indices = np.argmax(preds[0])
|
70 |
# st.write(class_indices)
|
71 |
|
72 |
# The corresponding maximum probability
|
73 |
-
class_probabilities = preds[0][class_indices]
|
74 |
|
75 |
# print(f"Class Index: {class_index}, Max Probability: {max_probability}")
|
76 |
# unprint below
|
77 |
# results_text = ""
|
78 |
-
predicted_defects = []
|
79 |
# if len(class_indices) > 0:
|
80 |
# for i, class_idx in enumerate(class_indices):
|
81 |
-
class_name = class_labels[class_indices]
|
82 |
-
results_text = f"{class_name} (Class {class_indices}): Probability {class_probabilities:.2f}\n"
|
83 |
-
predicted_defects.append(class_name)
|
84 |
# else:
|
85 |
# results_text = "No classes detected with a probability greater than the threshold."
|
|
|
|
|
|
|
|
|
|
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
# Display classification results in a text box
|
88 |
st.text_area("Classification Results:", value=results_text, height=200)
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
# Encode the uploaded image as Base64
|
91 |
base64_image = base64.b64encode(file_bytes).decode("utf-8")
|
92 |
image_data = f"data:image/jpeg;base64,{base64_image}"
|
|
|
66 |
|
67 |
# class_indices = np.where(preds[0] > threshold)[0]
|
68 |
# class_probabilities = preds[0][class_indices]
|
69 |
+
# class_indices = np.argmax(preds[0])
|
70 |
# st.write(class_indices)
|
71 |
|
72 |
# The corresponding maximum probability
|
73 |
+
# class_probabilities = preds[0][class_indices]
|
74 |
|
75 |
# print(f"Class Index: {class_index}, Max Probability: {max_probability}")
|
76 |
# unprint below
|
77 |
# results_text = ""
|
78 |
+
# predicted_defects = []
|
79 |
# if len(class_indices) > 0:
|
80 |
# for i, class_idx in enumerate(class_indices):
|
81 |
+
# class_name = class_labels[class_indices]
|
82 |
+
# results_text = f"{class_name} (Class {class_indices}): Probability {class_probabilities:.2f}\n"
|
83 |
+
# predicted_defects.append(class_name)
|
84 |
# else:
|
85 |
# results_text = "No classes detected with a probability greater than the threshold."
|
86 |
+
|
87 |
+
# Display classification results in a text box
|
88 |
+
# st.text_area("Classification Results:", value=results_text, height=200)
|
89 |
+
|
90 |
+
|
91 |
|
92 |
+
|
93 |
+
# Get the index of the class with the maximum probability
|
94 |
+
class_indices = np.argmax(preds[0])
|
95 |
+
|
96 |
+
# The corresponding maximum probability
|
97 |
+
class_probabilities = preds[0][class_indices]
|
98 |
+
|
99 |
+
# Get the class name for the predicted index
|
100 |
+
class_name = class_labels[class_indices]
|
101 |
+
|
102 |
+
# Prepare the results text
|
103 |
+
results_text = f"{class_name} (Class {class_indices}): Probability {class_probabilities:.2f}\n"
|
104 |
+
|
105 |
+
# Append the class name to the predicted defects list
|
106 |
+
predicted_defects = [class_name]
|
107 |
+
|
108 |
# Display classification results in a text box
|
109 |
st.text_area("Classification Results:", value=results_text, height=200)
|
110 |
|
111 |
+
|
112 |
+
|
113 |
+
|
114 |
+
|
115 |
+
|
116 |
+
|
117 |
+
|
118 |
# Encode the uploaded image as Base64
|
119 |
base64_image = base64.b64encode(file_bytes).decode("utf-8")
|
120 |
image_data = f"data:image/jpeg;base64,{base64_image}"
|