Spaces:
Sleeping
Sleeping
ariankhalfani
commited on
Commit
•
ae9edf6
1
Parent(s):
eef1e05
Update app.py
Browse files
app.py
CHANGED
@@ -59,7 +59,7 @@ def predict_image(input_image, name, age, medical_record, sex):
|
|
59 |
class_index = highest_confidence_result.cls.item()
|
60 |
if class_index == 0:
|
61 |
label = "Immature"
|
62 |
-
color = (0,
|
63 |
elif class_index == 1:
|
64 |
label = "Mature"
|
65 |
color = (255, 0, 0) # Red for Mature
|
@@ -69,9 +69,6 @@ def predict_image(input_image, name, age, medical_record, sex):
|
|
69 |
|
70 |
confidence = highest_confidence_result.conf.item()
|
71 |
xmin, ymin, xmax, ymax = map(int, highest_confidence_result.xyxy[0])
|
72 |
-
|
73 |
-
# Draw the bounding box
|
74 |
-
cv2.rectangle(image_with_boxes, (xmin, ymin), (xmax, ymax), color, 2)
|
75 |
|
76 |
# Calculate the average of box width and height
|
77 |
box_width = xmax - xmin
|
@@ -85,9 +82,9 @@ def predict_image(input_image, name, age, medical_record, sex):
|
|
85 |
center_x = int((xmin + xmax) / 2)
|
86 |
center_y = int((ymin + ymax) / 2)
|
87 |
|
88 |
-
# Draw the
|
89 |
-
cv2.circle(image_with_boxes, (center_x, center_y), radius,
|
90 |
-
|
91 |
# Enlarge font scale and thickness
|
92 |
font_scale = 1.0
|
93 |
thickness = 2
|
@@ -99,7 +96,7 @@ def predict_image(input_image, name, age, medical_record, sex):
|
|
99 |
# Put the label text with black background
|
100 |
cv2.putText(image_with_boxes, f'{label} {confidence:.2f}', (xmin, ymin - 10), cv2.FONT_HERSHEY_SIMPLEX, font_scale, (255, 255, 255), thickness)
|
101 |
|
102 |
-
raw_predictions.append(f"Label: {label}, Confidence: {confidence:.2f},
|
103 |
|
104 |
raw_predictions_str = "\n".join(raw_predictions)
|
105 |
|
@@ -114,7 +111,7 @@ def predict_image(input_image, name, age, medical_record, sex):
|
|
114 |
input_image.save(uploaded_folder / image_name)
|
115 |
pil_image_with_boxes.save(predicted_folder / image_name)
|
116 |
|
117 |
-
# Convert the predicted image to base64 for embedding in
|
118 |
buffered = BytesIO()
|
119 |
pil_image_with_boxes.save(buffered, format="PNG")
|
120 |
predicted_image_base64 = base64.b64encode(buffered.getvalue()).decode()
|
|
|
59 |
class_index = highest_confidence_result.cls.item()
|
60 |
if class_index == 0:
|
61 |
label = "Immature"
|
62 |
+
color = (0, 0, 255) # Blue for Immature
|
63 |
elif class_index == 1:
|
64 |
label = "Mature"
|
65 |
color = (255, 0, 0) # Red for Mature
|
|
|
69 |
|
70 |
confidence = highest_confidence_result.conf.item()
|
71 |
xmin, ymin, xmax, ymax = map(int, highest_confidence_result.xyxy[0])
|
|
|
|
|
|
|
72 |
|
73 |
# Calculate the average of box width and height
|
74 |
box_width = xmax - xmin
|
|
|
82 |
center_x = int((xmin + xmax) / 2)
|
83 |
center_y = int((ymin + ymax) / 2)
|
84 |
|
85 |
+
# Draw the circle at the center of the bounding box with the color corresponding to the label
|
86 |
+
cv2.circle(image_with_boxes, (center_x, center_y), radius, color, 2)
|
87 |
+
|
88 |
# Enlarge font scale and thickness
|
89 |
font_scale = 1.0
|
90 |
thickness = 2
|
|
|
96 |
# Put the label text with black background
|
97 |
cv2.putText(image_with_boxes, f'{label} {confidence:.2f}', (xmin, ymin - 10), cv2.FONT_HERSHEY_SIMPLEX, font_scale, (255, 255, 255), thickness)
|
98 |
|
99 |
+
raw_predictions.append(f"Label: {label}, Confidence: {confidence:.2f}, Circle Center: [{center_x}, {center_y}], Radius: {radius}")
|
100 |
|
101 |
raw_predictions_str = "\n".join(raw_predictions)
|
102 |
|
|
|
111 |
input_image.save(uploaded_folder / image_name)
|
112 |
pil_image_with_boxes.save(predicted_folder / image_name)
|
113 |
|
114 |
+
# Convert the predicted image to base64 for embedding in the XLSX file
|
115 |
buffered = BytesIO()
|
116 |
pil_image_with_boxes.save(buffered, format="PNG")
|
117 |
predicted_image_base64 = base64.b64encode(buffered.getvalue()).decode()
|