Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -72,7 +72,6 @@ def alpr_color_inference(image):
|
|
72 |
if not vehicle_boxes:
|
73 |
color_text = "No vehicle detected"
|
74 |
cropped_img = img
|
75 |
-
vehicle_img = img
|
76 |
else:
|
77 |
largest_vehicle = max(vehicle_boxes, key=lambda box: (box.xyxy[0][2] - box.xyxy[0][0]) * (box.xyxy[0][3] - box.xyxy[0][1]))
|
78 |
x1, y1, x2, y2 = map(int, largest_vehicle.xyxy[0].tolist())
|
@@ -84,25 +83,26 @@ def alpr_color_inference(image):
|
|
84 |
pred_idx = torch.argmax(probs).item()
|
85 |
pred_class = class_names[pred_idx]
|
86 |
confidence = probs[pred_idx].item()
|
87 |
-
|
|
|
88 |
color_text = f"{pred_class} ({confidence*100:.1f}%)"
|
89 |
|
90 |
detection_results = (f"Detected {len(results)} license plate(s): {', '.join(plate_texts)}"
|
91 |
if results else "No license plate detected 😔.")
|
92 |
|
93 |
-
return annotated_img,
|
94 |
|
95 |
# ------------------ Gradio UI ------------------
|
96 |
with gr.Blocks() as demo:
|
97 |
gr.Markdown("# License Plate + Vehicle Color Detection")
|
98 |
with gr.Row():
|
99 |
with gr.Column():
|
100 |
-
image_input = gr.Image(type="pil", label="Upload an image")
|
101 |
submit_btn = gr.Button("Run Detection")
|
102 |
with gr.Column():
|
103 |
-
plate_output = gr.Image(label="
|
104 |
-
vehicle_output = gr.Image(label="
|
105 |
-
cropped_output = gr.Image(label="Cropped Vehicle Region")
|
106 |
result_text = gr.Markdown(label="Results")
|
107 |
|
108 |
submit_btn.click(
|
|
|
72 |
if not vehicle_boxes:
|
73 |
color_text = "No vehicle detected"
|
74 |
cropped_img = img
|
|
|
75 |
else:
|
76 |
largest_vehicle = max(vehicle_boxes, key=lambda box: (box.xyxy[0][2] - box.xyxy[0][0]) * (box.xyxy[0][3] - box.xyxy[0][1]))
|
77 |
x1, y1, x2, y2 = map(int, largest_vehicle.xyxy[0].tolist())
|
|
|
83 |
pred_idx = torch.argmax(probs).item()
|
84 |
pred_class = class_names[pred_idx]
|
85 |
confidence = probs[pred_idx].item()
|
86 |
+
draw.rectangle((x1, y1, x2, y2), outline="blue", width=3)
|
87 |
+
draw.text((x1, max(y1 - 10, 0)), f"{pred_class} ({confidence*100:.1f}%)", fill="blue")
|
88 |
color_text = f"{pred_class} ({confidence*100:.1f}%)"
|
89 |
|
90 |
detection_results = (f"Detected {len(results)} license plate(s): {', '.join(plate_texts)}"
|
91 |
if results else "No license plate detected 😔.")
|
92 |
|
93 |
+
return annotated_img, cropped_img, cropped_img, f"{detection_results}\nVehicle Color: {color_text}"
|
94 |
|
95 |
# ------------------ Gradio UI ------------------
|
96 |
with gr.Blocks() as demo:
|
97 |
gr.Markdown("# License Plate + Vehicle Color Detection")
|
98 |
with gr.Row():
|
99 |
with gr.Column():
|
100 |
+
image_input = gr.Image(type="pil", label="Upload an image", show_clear_button=True)
|
101 |
submit_btn = gr.Button("Run Detection")
|
102 |
with gr.Column():
|
103 |
+
plate_output = gr.Image(label="Combined Detection Output")
|
104 |
+
vehicle_output = gr.Image(label="(Optional) Cropped Vehicle")
|
105 |
+
cropped_output = gr.Image(label="(Optional) Cropped Vehicle Region")
|
106 |
result_text = gr.Markdown(label="Results")
|
107 |
|
108 |
submit_btn.click(
|