Update app.py
Browse files
app.py
CHANGED
|
@@ -19,7 +19,7 @@ CREATE TABLE IF NOT EXISTS vehicles (
|
|
| 19 |
date TEXT NOT NULL,
|
| 20 |
time TEXT NOT NULL,
|
| 21 |
plate TEXT,
|
| 22 |
-
|
| 23 |
is_ev INTEGER NOT NULL DEFAULT 0,
|
| 24 |
toll REAL DEFAULT 0.0,
|
| 25 |
parking REAL DEFAULT 0.0,
|
|
@@ -75,10 +75,10 @@ def read_plate(plate_img):
|
|
| 75 |
return "UNKNOWN"
|
| 76 |
# -----------added to calculate discount
|
| 77 |
|
| 78 |
-
is_ev = (
|
| 79 |
|
| 80 |
discount = calculate_discounts(
|
| 81 |
-
|
| 82 |
is_ev
|
| 83 |
)
|
| 84 |
|
|
@@ -132,7 +132,7 @@ def detect_vehicle_type(image):
|
|
| 132 |
|
| 133 |
# -------------------- Discount Engine --------------------
|
| 134 |
|
| 135 |
-
def calculate_discounts(
|
| 136 |
|
| 137 |
toll = 0
|
| 138 |
parking = 0
|
|
@@ -144,13 +144,13 @@ def calculate_discounts(vehicle_type, is_ev):
|
|
| 144 |
|
| 145 |
parking = 100
|
| 146 |
|
| 147 |
-
if
|
| 148 |
incentive = 10000
|
| 149 |
|
| 150 |
-
elif
|
| 151 |
incentive = 50000
|
| 152 |
|
| 153 |
-
elif
|
| 154 |
incentive = 75000
|
| 155 |
|
| 156 |
else:
|
|
@@ -274,7 +274,7 @@ def process_image(img):
|
|
| 274 |
return (
|
| 275 |
image,
|
| 276 |
plate_text,
|
| 277 |
-
|
| 278 |
f"{discount['toll_discount']}%",
|
| 279 |
f"{discount['parking_discount']}%",
|
| 280 |
f"₹{discount['government_incentive']}",
|
|
@@ -285,11 +285,11 @@ def process_image(img):
|
|
| 285 |
plate_img = image.crop((x1, y1, x2, y2))
|
| 286 |
|
| 287 |
plate_text = read_plate(plate_img)
|
| 288 |
-
|
| 289 |
is_ev = vehicle_type == "EV"
|
| 290 |
|
| 291 |
discount = calculate_discounts(
|
| 292 |
-
|
| 293 |
is_ev
|
| 294 |
)
|
| 295 |
|
|
@@ -301,7 +301,7 @@ def process_image(img):
|
|
| 301 |
date,
|
| 302 |
time,
|
| 303 |
plate,
|
| 304 |
-
|
| 305 |
is_ev,
|
| 306 |
toll,
|
| 307 |
parking,
|
|
@@ -313,7 +313,7 @@ def process_image(img):
|
|
| 313 |
now.strftime("%Y-%m-%d"),
|
| 314 |
now.strftime("%H:%M:%S"),
|
| 315 |
plate_text,
|
| 316 |
-
|
| 317 |
int(is_ev),
|
| 318 |
discount["toll_discount"],
|
| 319 |
discount["parking_discount"],
|
|
@@ -325,11 +325,11 @@ def process_image(img):
|
|
| 325 |
draw.rectangle([x1, y1, x2, y2], outline="red", width=3)
|
| 326 |
draw.text(
|
| 327 |
(x1, y1-15),
|
| 328 |
-
f"{
|
| 329 |
fill="red"
|
| 330 |
)
|
| 331 |
|
| 332 |
-
return image, plate_text,
|
| 333 |
|
| 334 |
# -------------------- Gradio UI --------------------
|
| 335 |
css = """
|
|
|
|
| 19 |
date TEXT NOT NULL,
|
| 20 |
time TEXT NOT NULL,
|
| 21 |
plate TEXT,
|
| 22 |
+
type TEXT,
|
| 23 |
is_ev INTEGER NOT NULL DEFAULT 0,
|
| 24 |
toll REAL DEFAULT 0.0,
|
| 25 |
parking REAL DEFAULT 0.0,
|
|
|
|
| 75 |
return "UNKNOWN"
|
| 76 |
# -----------added to calculate discount
|
| 77 |
|
| 78 |
+
is_ev = (type == "EV")
|
| 79 |
|
| 80 |
discount = calculate_discounts(
|
| 81 |
+
type,
|
| 82 |
is_ev
|
| 83 |
)
|
| 84 |
|
|
|
|
| 132 |
|
| 133 |
# -------------------- Discount Engine --------------------
|
| 134 |
|
| 135 |
+
def calculate_discounts(type, is_ev):
|
| 136 |
|
| 137 |
toll = 0
|
| 138 |
parking = 0
|
|
|
|
| 144 |
|
| 145 |
parking = 100
|
| 146 |
|
| 147 |
+
if type == "Car":
|
| 148 |
incentive = 10000
|
| 149 |
|
| 150 |
+
elif type == "Bus":
|
| 151 |
incentive = 50000
|
| 152 |
|
| 153 |
+
elif type == "Truck":
|
| 154 |
incentive = 75000
|
| 155 |
|
| 156 |
else:
|
|
|
|
| 274 |
return (
|
| 275 |
image,
|
| 276 |
plate_text,
|
| 277 |
+
type,
|
| 278 |
f"{discount['toll_discount']}%",
|
| 279 |
f"{discount['parking_discount']}%",
|
| 280 |
f"₹{discount['government_incentive']}",
|
|
|
|
| 285 |
plate_img = image.crop((x1, y1, x2, y2))
|
| 286 |
|
| 287 |
plate_text = read_plate(plate_img)
|
| 288 |
+
type = classify_plate_color(plate_img)
|
| 289 |
is_ev = vehicle_type == "EV"
|
| 290 |
|
| 291 |
discount = calculate_discounts(
|
| 292 |
+
type,
|
| 293 |
is_ev
|
| 294 |
)
|
| 295 |
|
|
|
|
| 301 |
date,
|
| 302 |
time,
|
| 303 |
plate,
|
| 304 |
+
type,
|
| 305 |
is_ev,
|
| 306 |
toll,
|
| 307 |
parking,
|
|
|
|
| 313 |
now.strftime("%Y-%m-%d"),
|
| 314 |
now.strftime("%H:%M:%S"),
|
| 315 |
plate_text,
|
| 316 |
+
type,
|
| 317 |
int(is_ev),
|
| 318 |
discount["toll_discount"],
|
| 319 |
discount["parking_discount"],
|
|
|
|
| 325 |
draw.rectangle([x1, y1, x2, y2], outline="red", width=3)
|
| 326 |
draw.text(
|
| 327 |
(x1, y1-15),
|
| 328 |
+
f"{type} | {plate_category} | {plate_text}",
|
| 329 |
fill="red"
|
| 330 |
)
|
| 331 |
|
| 332 |
+
return image, plate_text, type, get_dashboard()
|
| 333 |
|
| 334 |
# -------------------- Gradio UI --------------------
|
| 335 |
css = """
|