Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ from hugsvision.inference.VisionClassifierInference import VisionClassifierInfer
|
|
3 |
import gradio as gr
|
4 |
import cv2
|
5 |
import numpy as np
|
|
|
6 |
|
7 |
# Load the pretrained ViT model and feature extractor
|
8 |
path = "mrm8488/vit-base-patch16-224_finetuned-kvasirv2-colonoscopy"
|
@@ -15,18 +16,30 @@ classifier = VisionClassifierInference(
|
|
15 |
model=model,
|
16 |
)
|
17 |
|
18 |
-
# Define
|
19 |
def classify_image_with_overlay(img):
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
#
|
24 |
-
|
25 |
-
|
26 |
-
#
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
iface = gr.Interface(
|
32 |
fn=classify_image_with_overlay,
|
|
|
3 |
import gradio as gr
|
4 |
import cv2
|
5 |
import numpy as np
|
6 |
+
from PIL import Image # Importe a classe Image do m贸dulo PIL (Pillow)
|
7 |
|
8 |
# Load the pretrained ViT model and feature extractor
|
9 |
path = "mrm8488/vit-base-patch16-224_finetuned-kvasirv2-colonoscopy"
|
|
|
16 |
model=model,
|
17 |
)
|
18 |
|
19 |
+
# Define uma fun莽茫o para classificar e sobrepor o r贸tulo na imagem
|
20 |
def classify_image_with_overlay(img):
|
21 |
+
# Predict the label
|
22 |
+
label = classifier.predict(img_path=img)
|
23 |
+
|
24 |
+
# Load the image using OpenCV
|
25 |
+
image = cv2.imread(img)
|
26 |
+
|
27 |
+
# Add a white rectangle for the label
|
28 |
+
font = cv2.FONT_HERSHEY_SIMPLEX
|
29 |
+
org = (10, 30)
|
30 |
+
font_scale = 1
|
31 |
+
color = (255, 255, 255) # White color
|
32 |
+
thickness = 2
|
33 |
+
text_size = cv2.getTextSize(label, font, font_scale, thickness)[0]
|
34 |
+
cv2.rectangle(image, (org[0] - 10, org[1] - text_size[1] - 10), (org[0] + text_size[0], org[1]), color, cv2.FILLED)
|
35 |
+
|
36 |
+
# Put the label text on the white rectangle
|
37 |
+
cv2.putText(image, label, org, font, font_scale, (0, 0, 0), thickness, cv2.LINE_AA)
|
38 |
+
|
39 |
+
# Convert the image to RGB format for Gradio using PIL's Image class
|
40 |
+
image_pil = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
|
41 |
+
|
42 |
+
return image_pil
|
43 |
|
44 |
iface = gr.Interface(
|
45 |
fn=classify_image_with_overlay,
|