Update app.py
Browse files
app.py
CHANGED
@@ -17,28 +17,16 @@ classifier = VisionClassifierInference(
|
|
17 |
|
18 |
# Define a function to classify and overlay the label on the image
|
19 |
def classify_image_with_overlay(img):
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
#
|
24 |
-
|
25 |
-
|
26 |
-
#
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
color = (255, 255, 255) # White color
|
31 |
-
thickness = 2
|
32 |
-
text_size = cv2.getTextSize(label, font, font_scale, thickness)[0]
|
33 |
-
cv2.rectangle(image, (org[0] - 10, org[1] - text_size[1] - 10), (org[0] + text_size[0], org[1]), color, cv2.FILLED)
|
34 |
-
|
35 |
-
# Put the label text on the white rectangle
|
36 |
-
cv2.putText(image, label, org, font, font_scale, (0, 0, 0), thickness, cv2.LINE_AA)
|
37 |
-
|
38 |
-
# Convert the image to RGB format for Gradio
|
39 |
-
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
40 |
-
|
41 |
-
return image_rgb
|
42 |
|
43 |
iface = gr.Interface(
|
44 |
fn=classify_image_with_overlay,
|
|
|
17 |
|
18 |
# Define a function to classify and overlay the label on the image
|
19 |
def classify_image_with_overlay(img):
|
20 |
+
# Converte a imagem NumPy ndarray para um objeto Pillow Image
|
21 |
+
img_pil = Image.fromarray(img)
|
22 |
+
|
23 |
+
# Realiza a classificação usando o modelo e adiciona o rótulo previsto à imagem
|
24 |
+
image_with_text = classificar_imagem(img_pil)
|
25 |
+
|
26 |
+
# Converte a imagem resultante de volta para NumPy ndarray
|
27 |
+
image_with_text_np = np.array(image_with_text)
|
28 |
+
|
29 |
+
return image_with_text_np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
iface = gr.Interface(
|
32 |
fn=classify_image_with_overlay,
|