Gabolozano commited on
Commit
1ef8213
·
verified ·
1 Parent(s): 447f128

Create app.py

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