Update app.py
Browse files
app.py
CHANGED
@@ -22,7 +22,7 @@ def classify_image_with_overlay(img):
|
|
22 |
img_pil = Image.fromarray(img)
|
23 |
|
24 |
# Predict the label and probability
|
25 |
-
|
26 |
|
27 |
# Load the image using OpenCV
|
28 |
image = cv2.cvtColor(np.array(img_pil), cv2.COLOR_RGB2BGR)
|
@@ -33,17 +33,22 @@ def classify_image_with_overlay(img):
|
|
33 |
font_scale = 1.5 # Increase the font size
|
34 |
color = (255, 255, 255) # White color
|
35 |
thickness = 2
|
36 |
-
|
|
|
|
|
37 |
cv2.rectangle(image, (org[0] - 10, org[1] - text_size[1] - 10), (org[0] + text_size[0], org[1]), color, cv2.FILLED)
|
38 |
|
39 |
# Put the label text on the white rectangle
|
40 |
-
cv2.putText(image,
|
41 |
|
42 |
# Resize the image to a larger size
|
43 |
image = cv2.resize(image, (800, 800)) # Defina o tamanho desejado aqui
|
44 |
|
45 |
return image
|
46 |
|
|
|
|
|
|
|
47 |
iface = gr.Interface(
|
48 |
fn=classify_image_with_overlay,
|
49 |
inputs=gr.inputs.Image(),
|
|
|
22 |
img_pil = Image.fromarray(img)
|
23 |
|
24 |
# Predict the label and probability
|
25 |
+
prediction = classifier.predict_image(img=img_pil)
|
26 |
|
27 |
# Load the image using OpenCV
|
28 |
image = cv2.cvtColor(np.array(img_pil), cv2.COLOR_RGB2BGR)
|
|
|
33 |
font_scale = 1.5 # Increase the font size
|
34 |
color = (255, 255, 255) # White color
|
35 |
thickness = 2
|
36 |
+
text = f"{prediction['label']}: {prediction['probability']:.2f}"
|
37 |
+
|
38 |
+
text_size = cv2.getTextSize(text, font, font_scale, thickness)[0]
|
39 |
cv2.rectangle(image, (org[0] - 10, org[1] - text_size[1] - 10), (org[0] + text_size[0], org[1]), color, cv2.FILLED)
|
40 |
|
41 |
# Put the label text on the white rectangle
|
42 |
+
cv2.putText(image, text, org, font, font_scale, (0, 0, 0), thickness, cv2.LINE_AA)
|
43 |
|
44 |
# Resize the image to a larger size
|
45 |
image = cv2.resize(image, (800, 800)) # Defina o tamanho desejado aqui
|
46 |
|
47 |
return image
|
48 |
|
49 |
+
# ...
|
50 |
+
|
51 |
+
|
52 |
iface = gr.Interface(
|
53 |
fn=classify_image_with_overlay,
|
54 |
inputs=gr.inputs.Image(),
|