Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
title: ObjectDetectionApp
|
3 |
-
|
4 |
-
colorFrom: green
|
5 |
-
colorTo: green
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 5.
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
title: ObjectDetectionApp
|
3 |
+
app_file: myapp.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
+
sdk_version: 5.7.1
|
|
|
|
|
6 |
---
|
|
|
|
myapp.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image, ImageDraw
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
objDetector = pipeline(task = "object-detection",
|
6 |
+
model = "facebook/detr-resnet-50")
|
7 |
+
|
8 |
+
def detect_objects(image): # image is a NumPy array
|
9 |
+
image = Image.fromarray(image) # convert from NumPy array to PIL image
|
10 |
+
draw = ImageDraw.Draw(image) # create a drawable image
|
11 |
+
results = objDetector(image) # detect objects in image
|
12 |
+
|
13 |
+
for obj in results:
|
14 |
+
if obj['score'] < 0.9:
|
15 |
+
continue
|
16 |
+
box = [
|
17 |
+
obj['box']['xmin'],
|
18 |
+
obj['box']['ymin'],
|
19 |
+
obj['box']['xmax'],
|
20 |
+
obj['box']['ymax']
|
21 |
+
]
|
22 |
+
draw.rectangle(box, outline='yellow', width=5)
|
23 |
+
draw.text((box[0], box[1] - 15), obj['label'], fill='white')
|
24 |
+
|
25 |
+
return image
|
26 |
+
|
27 |
+
demo = gr.Interface(
|
28 |
+
fn = detect_objects,
|
29 |
+
inputs = gr.Image(label = "Upload Image"),
|
30 |
+
outputs = gr.Image(label = "Detected Objects")
|
31 |
+
)
|
32 |
+
|
33 |
+
demo.launch()
|