Spaces:
Sleeping
Sleeping
barathvasan-dev commited on
Commit ·
b5ec393
1
Parent(s): 7cf0fd2
Return timestamp and plate only
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import re
|
|
|
|
| 2 |
|
| 3 |
import cv2
|
| 4 |
import gradio as gr
|
|
@@ -48,11 +49,16 @@ def select_best(plates):
|
|
| 48 |
return plate_text, best
|
| 49 |
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
def detect(image):
|
|
|
|
| 52 |
results = model(image)
|
| 53 |
boxes = results[0].boxes
|
| 54 |
if boxes is None or len(boxes) == 0:
|
| 55 |
-
return "
|
| 56 |
|
| 57 |
height, width = image.shape[:2]
|
| 58 |
plates = []
|
|
@@ -98,9 +104,11 @@ def detect(image):
|
|
| 98 |
|
| 99 |
plate_text, best_plate = select_best(plates)
|
| 100 |
if not plate_text:
|
| 101 |
-
plate_text = "
|
| 102 |
|
| 103 |
-
|
|
|
|
|
|
|
| 104 |
|
| 105 |
|
| 106 |
demo = gr.Interface(
|
|
|
|
| 1 |
import re
|
| 2 |
+
from datetime import datetime
|
| 3 |
|
| 4 |
import cv2
|
| 5 |
import gradio as gr
|
|
|
|
| 49 |
return plate_text, best
|
| 50 |
|
| 51 |
|
| 52 |
+
def current_timestamp():
|
| 53 |
+
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 54 |
+
|
| 55 |
+
|
| 56 |
def detect(image):
|
| 57 |
+
timestamp = current_timestamp()
|
| 58 |
results = model(image)
|
| 59 |
boxes = results[0].boxes
|
| 60 |
if boxes is None or len(boxes) == 0:
|
| 61 |
+
return f"{timestamp} |", {"timestamp": timestamp, "plate": ""}
|
| 62 |
|
| 63 |
height, width = image.shape[:2]
|
| 64 |
plates = []
|
|
|
|
| 104 |
|
| 105 |
plate_text, best_plate = select_best(plates)
|
| 106 |
if not plate_text:
|
| 107 |
+
plate_text = ""
|
| 108 |
|
| 109 |
+
text_output = f"{timestamp} | {plate_text}" if plate_text else f"{timestamp} |"
|
| 110 |
+
json_output = {"timestamp": timestamp, "plate": plate_text}
|
| 111 |
+
return text_output, json_output
|
| 112 |
|
| 113 |
|
| 114 |
demo = gr.Interface(
|