Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import os
|
3 |
import gradio as gr
|
4 |
from transformers import pipeline, DetrForObjectDetection, DetrConfig, DetrImageProcessor
|
@@ -35,25 +34,6 @@ model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50", config
|
|
35 |
image_processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
36 |
od_pipe = pipeline(task='object-detection', model=model, image_processor=image_processor)
|
37 |
|
38 |
-
def get_pipeline_prediction(pil_image):
|
39 |
-
# Run the object detection pipeline
|
40 |
-
pipeline_output = od_pipe(pil_image)
|
41 |
-
|
42 |
-
# Draw the detection results on the image
|
43 |
-
processed_image = draw_detections(pil_image, pipeline_output)
|
44 |
-
|
45 |
-
# Provide both the image and the JSON detection results
|
46 |
-
return processed_image, pipeline_output
|
47 |
-
|
48 |
-
demo = gr.Interface(
|
49 |
-
fn=get_pipeline_prediction,
|
50 |
-
inputs=gr.Image(label="Input image", type="pil"),
|
51 |
-
outputs=[
|
52 |
-
gr.Image(label="Annotated Image"),
|
53 |
-
gr.JSON(label="Detected Objects")
|
54 |
-
]
|
55 |
-
)
|
56 |
-
|
57 |
def get_pipeline_prediction(pil_image):
|
58 |
try:
|
59 |
# Run the object detection pipeline
|
@@ -69,5 +49,14 @@ def get_pipeline_prediction(pil_image):
|
|
69 |
print(f"An error occurred: {str(e)}")
|
70 |
# Return a message and an empty JSON
|
71 |
return pil_image, {"error": str(e)}
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
demo.launch()
|
|
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline, DetrForObjectDetection, DetrConfig, DetrImageProcessor
|
|
|
34 |
image_processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
35 |
od_pipe = pipeline(task='object-detection', model=model, image_processor=image_processor)
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
def get_pipeline_prediction(pil_image):
|
38 |
try:
|
39 |
# Run the object detection pipeline
|
|
|
49 |
print(f"An error occurred: {str(e)}")
|
50 |
# Return a message and an empty JSON
|
51 |
return pil_image, {"error": str(e)}
|
52 |
+
|
53 |
+
demo = gr.Interface(
|
54 |
+
fn=get_pipeline_prediction,
|
55 |
+
inputs=gr.Image(label="Input image", type="pil"),
|
56 |
+
outputs=[
|
57 |
+
gr.Image(label="Annotated Image"),
|
58 |
+
gr.JSON(label="Detected Objects")
|
59 |
+
]
|
60 |
+
)
|
61 |
+
|
62 |
demo.launch()
|