Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
# app.py
|
2 |
|
3 |
-
# app.py
|
4 |
-
|
5 |
from transformers import pipeline
|
6 |
import gradio as gr
|
7 |
from PIL import Image, ImageDraw, ImageFont
|
@@ -25,7 +23,6 @@ def get_color(label):
|
|
25 |
# Detection function
|
26 |
def detect_objects(img):
|
27 |
results = detector(img)
|
28 |
-
|
29 |
draw = ImageDraw.Draw(img)
|
30 |
font = ImageFont.load_default()
|
31 |
|
@@ -44,12 +41,12 @@ def detect_objects(img):
|
|
44 |
|
45 |
# Prepare label with confidence
|
46 |
label_text = f"{label} ({score:.2f})"
|
47 |
-
|
48 |
-
text_background = [
|
49 |
|
50 |
# Draw background for text
|
51 |
draw.rectangle(text_background, fill=color)
|
52 |
-
draw.text((
|
53 |
|
54 |
return img
|
55 |
|
|
|
1 |
# app.py
|
2 |
|
|
|
|
|
3 |
from transformers import pipeline
|
4 |
import gradio as gr
|
5 |
from PIL import Image, ImageDraw, ImageFont
|
|
|
23 |
# Detection function
|
24 |
def detect_objects(img):
|
25 |
results = detector(img)
|
|
|
26 |
draw = ImageDraw.Draw(img)
|
27 |
font = ImageFont.load_default()
|
28 |
|
|
|
41 |
|
42 |
# Prepare label with confidence
|
43 |
label_text = f"{label} ({score:.2f})"
|
44 |
+
text_bbox = draw.textbbox((box["xmin"], box["ymin"]), label_text, font=font)
|
45 |
+
text_background = [text_bbox[0], text_bbox[1], text_bbox[2], text_bbox[3]]
|
46 |
|
47 |
# Draw background for text
|
48 |
draw.rectangle(text_background, fill=color)
|
49 |
+
draw.text((text_bbox[0], text_bbox[1]), label_text, fill="black", font=font)
|
50 |
|
51 |
return img
|
52 |
|