Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -48,7 +48,7 @@ model = genai.GenerativeModel(model_name="gemini-1.5-flash-latest",
|
|
48 |
generation_config=generation_config,
|
49 |
safety_settings=safety_settings)
|
50 |
|
51 |
-
input_prompt_template = """give me the info of the car (if an info is not available juste write "introuvable"):
|
52 |
- plate:
|
53 |
- model:
|
54 |
- color: """
|
@@ -92,7 +92,7 @@ def detect_objects(image):
|
|
92 |
|
93 |
# Loop through detections and filter only "car" class (ID 3 for COCO dataset)
|
94 |
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
|
95 |
-
if model.config.id2label[label.item()] == 'car' and score.item() > 0.9:
|
96 |
box = [round(i, 2) for i in box.tolist()]
|
97 |
# Crop the detected car
|
98 |
cropped_car = image.crop(box)
|
@@ -102,7 +102,7 @@ def detect_objects(image):
|
|
102 |
|
103 |
# Draw bounding box around the car
|
104 |
draw.rectangle(box, outline="red", width=3)
|
105 |
-
draw.text((box[0], box[1]), f"
|
106 |
|
107 |
return image, detected_cars
|
108 |
|
@@ -135,7 +135,7 @@ def process_generate(files):
|
|
135 |
car_info_list = []
|
136 |
for car_bytes, box in detected_cars:
|
137 |
car_info = generate_gemini_response(input_prompt_template, car_bytes)
|
138 |
-
car_info_list.append(f"
|
139 |
|
140 |
return detected_image, "\n".join(car_info_list)
|
141 |
|
|
|
48 |
generation_config=generation_config,
|
49 |
safety_settings=safety_settings)
|
50 |
|
51 |
+
input_prompt_template = """give me the info of the car/truck (if an info is not available juste write "introuvable"):
|
52 |
- plate:
|
53 |
- model:
|
54 |
- color: """
|
|
|
92 |
|
93 |
# Loop through detections and filter only "car" class (ID 3 for COCO dataset)
|
94 |
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
|
95 |
+
if (model.config.id2label[label.item()] == 'car' or model.config.id2label[label.item()] == 'truck' ) and score.item() > 0.9:
|
96 |
box = [round(i, 2) for i in box.tolist()]
|
97 |
# Crop the detected car
|
98 |
cropped_car = image.crop(box)
|
|
|
102 |
|
103 |
# Draw bounding box around the car
|
104 |
draw.rectangle(box, outline="red", width=3)
|
105 |
+
draw.text((box[0], box[1]), f"véhicule: {round(score.item(), 2)}", fill="red")
|
106 |
|
107 |
return image, detected_cars
|
108 |
|
|
|
135 |
car_info_list = []
|
136 |
for car_bytes, box in detected_cars:
|
137 |
car_info = generate_gemini_response(input_prompt_template, car_bytes)
|
138 |
+
car_info_list.append(f"véhicule aux coordonnées {box}:\n{car_info}\n")
|
139 |
|
140 |
return detected_image, "\n".join(car_info_list)
|
141 |
|