Varun commited on
Commit
2932b3e
·
1 Parent(s): 803b87c

Implement object detection functionality in app.py using Gradio and DiffusionPipeline

Browse files
Files changed (2) hide show
  1. app.py +28 -4
  2. requirements.txt +5 -0
app.py CHANGED
@@ -1,9 +1,33 @@
1
  import gradio as gr
 
 
2
 
 
 
 
 
3
 
4
- def greet(name):
5
- return "Hello " + name + "!!"
6
 
 
 
 
7
 
8
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
9
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from diffusers import DiffusionPipeline
3
+ import torch
4
 
5
+ # Initialize the pipeline
6
+ pipe = DiffusionPipeline.from_pretrained("Lookingsoft-team/object_detection")
7
+ if torch.cuda.is_available():
8
+ pipe = pipe.to("cuda")
9
 
 
 
10
 
11
+ def detect_objects(image):
12
+ if image is None:
13
+ return None
14
 
15
+ # Process the image through the pipeline
16
+ # Note: This is a placeholder - actual processing will depend on the model's specific requirements
17
+ results = pipe(image=image)
18
+
19
+ # Return the processed image with detections
20
+ return results.images[0]
21
+
22
+
23
+ # Create Gradio interface
24
+ demo = gr.Interface(
25
+ fn=detect_objects,
26
+ inputs=gr.Image(type="pil"),
27
+ outputs=gr.Image(type="pil"),
28
+ title="Object Detection",
29
+ description="Upload an image and the model will detect objects in it!",
30
+ )
31
+
32
+ if __name__ == "__main__":
33
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio>=5.32.1
2
+ torch
3
+ diffusers
4
+ transformers
5
+ accelerate