Spaces:
Running
Running
Gabolozano
commited on
Commit
•
d4c3acc
1
Parent(s):
945a330
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,32 @@
|
|
1 |
-
|
2 |
-
import
|
3 |
-
from
|
4 |
-
import
|
5 |
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50", revision="no_timm")
|
12 |
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
#
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import pipeline
|
4 |
+
from transformers import DetrForObjectDetection, DetrConfig
|
5 |
|
6 |
+
# Initialize the configuration for DetrForObjectDetection
|
7 |
+
config = DetrConfig.from_pretrained("facebook/detr-resnet-50")
|
8 |
|
9 |
+
# Create the model for object detection using the specified configuration
|
10 |
+
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50", config=config)
|
|
|
11 |
|
12 |
+
# Initialize the object detection pipeline
|
13 |
+
od_pipe = pipeline(task='object-detection', model=model)
|
14 |
|
15 |
+
def get_pipeline_prediction(pil_image):
|
16 |
+
# Run the object detection pipeline on the input image
|
17 |
+
pipeline_output = od_pipe(pil_image)
|
18 |
+
|
19 |
+
# You might need to implement or adjust the rendering function based on the `pipeline_output`
|
20 |
+
# The `render_results_in_image` function is assumed here to draw bounding boxes and labels on the input image,
|
21 |
+
# but you'll need to define it according to your specific needs.
|
22 |
+
# For now, the output is directly returned since the question doesn't define `render_results_in_image`.
|
23 |
+
return pipeline_output
|
24 |
|
25 |
+
demo = gr.Interface(
|
26 |
+
fn=get_pipeline_prediction,
|
27 |
+
inputs=gr.Image(label="Input image",
|
28 |
+
type="pil"),
|
29 |
+
outputs=gr.JSON(label="Detected objects") # Adjusted to show JSON output if rendering function is not defined
|
30 |
+
)
|
31 |
+
|
32 |
+
demo.launch()
|