Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -78,10 +78,19 @@ def generate_gemini_response(input_prompt, image):
|
|
78 |
|
79 |
# Object detection part
|
80 |
def detect_objects(image):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50", revision="no_timm")
|
82 |
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50", revision="no_timm")
|
83 |
-
|
84 |
-
|
|
|
85 |
outputs = model(**inputs)
|
86 |
|
87 |
target_sizes = torch.tensor([image.size[::-1]])
|
@@ -106,6 +115,7 @@ def detect_objects(image):
|
|
106 |
|
107 |
return image, detected_cars
|
108 |
|
|
|
109 |
def image_to_bytes(img):
|
110 |
# Convert a PIL image to bytes
|
111 |
from io import BytesIO
|
|
|
78 |
|
79 |
# Object detection part
|
80 |
def detect_objects(image):
|
81 |
+
# Ensure the image is in RGB mode
|
82 |
+
if image.mode != "RGB":
|
83 |
+
image = image.convert("RGB")
|
84 |
+
|
85 |
+
# Convert the image to a numpy array
|
86 |
+
image_np = np.array(image)
|
87 |
+
|
88 |
+
# Load the processor and model
|
89 |
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50", revision="no_timm")
|
90 |
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50", revision="no_timm")
|
91 |
+
|
92 |
+
# Process the image for detection
|
93 |
+
inputs = processor(images=image_np, return_tensors="pt")
|
94 |
outputs = model(**inputs)
|
95 |
|
96 |
target_sizes = torch.tensor([image.size[::-1]])
|
|
|
115 |
|
116 |
return image, detected_cars
|
117 |
|
118 |
+
|
119 |
def image_to_bytes(img):
|
120 |
# Convert a PIL image to bytes
|
121 |
from io import BytesIO
|