Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,7 +62,6 @@ def analyze_video(input_video_path, sensitivity, progress=gr.Progress()):
|
|
| 62 |
out = cv2.VideoWriter(raw_output, fourcc, fps, (width, height))
|
| 63 |
morph_kernel = np.ones((5, 5), np.uint8)
|
| 64 |
|
| 65 |
-
# Calculate threshold based on user slider (e.g., 10% = 0.10)
|
| 66 |
drift_threshold = width * (sensitivity / 100.0)
|
| 67 |
frame_count = 0
|
| 68 |
alerts_triggered = 0
|
|
@@ -71,7 +70,6 @@ def analyze_video(input_video_path, sensitivity, progress=gr.Progress()):
|
|
| 71 |
ret, frame = cap.read()
|
| 72 |
if not ret: break
|
| 73 |
|
| 74 |
-
# Report progress to the UI
|
| 75 |
frame_count += 1
|
| 76 |
if frame_count % 5 == 0:
|
| 77 |
progress(frame_count / total_frames, desc=f"Processing AI Vision: Frame {frame_count}/{total_frames}")
|
|
@@ -108,9 +106,8 @@ def analyze_video(input_video_path, sensitivity, progress=gr.Progress()):
|
|
| 108 |
web_output = "ldobj_final.mp4"
|
| 109 |
os.system(f"ffmpeg -y -i {raw_output} -c:v libx264 -preset fast -pix_fmt yuv420p -movflags +faststart {web_output}")
|
| 110 |
|
| 111 |
-
# Calculate Telemetry
|
| 112 |
process_time = time.time() - start_time
|
| 113 |
-
avg_fps = frame_count / process_time
|
| 114 |
|
| 115 |
telemetry_report = (
|
| 116 |
f"✅ Analysis Complete\n"
|
|
@@ -132,13 +129,13 @@ footer { visibility: hidden; }
|
|
| 132 |
.sub-title { text-align: center; color: #888; margin-top: 0px; margin-bottom: 30px; }
|
| 133 |
"""
|
| 134 |
|
| 135 |
-
|
|
|
|
| 136 |
gr.HTML("<h1 class='glow-title'>🛡️ LDobj ADAS Command Center</h1>")
|
| 137 |
gr.HTML("<h3 class='sub-title'>Advanced Driver Assistance System • Neural Lane Tracking</h3>")
|
| 138 |
|
| 139 |
with gr.Group():
|
| 140 |
with gr.Row():
|
| 141 |
-
# LEFT COLUMN: Controls
|
| 142 |
with gr.Column(scale=4):
|
| 143 |
gr.Markdown("### 1. Input Source")
|
| 144 |
video_in = gr.Video(label="Dashcam Feed", elem_id="video-in")
|
|
@@ -152,7 +149,6 @@ with gr.Blocks(theme=gr.themes.Slate(primary_hue="red")) as app:
|
|
| 152 |
|
| 153 |
run_btn = gr.Button("INITIALIZE SCAN", variant="primary", size="lg")
|
| 154 |
|
| 155 |
-
# RIGHT COLUMN: Output
|
| 156 |
with gr.Column(scale=5):
|
| 157 |
gr.Markdown("### Live Output Feed")
|
| 158 |
video_out = gr.Video(label="LDobj Processed Feed", interactive=False, autoplay=True, elem_id="video-out")
|
|
@@ -167,4 +163,10 @@ with gr.Blocks(theme=gr.themes.Slate(primary_hue="red")) as app:
|
|
| 167 |
)
|
| 168 |
|
| 169 |
if __name__ == "__main__":
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
out = cv2.VideoWriter(raw_output, fourcc, fps, (width, height))
|
| 63 |
morph_kernel = np.ones((5, 5), np.uint8)
|
| 64 |
|
|
|
|
| 65 |
drift_threshold = width * (sensitivity / 100.0)
|
| 66 |
frame_count = 0
|
| 67 |
alerts_triggered = 0
|
|
|
|
| 70 |
ret, frame = cap.read()
|
| 71 |
if not ret: break
|
| 72 |
|
|
|
|
| 73 |
frame_count += 1
|
| 74 |
if frame_count % 5 == 0:
|
| 75 |
progress(frame_count / total_frames, desc=f"Processing AI Vision: Frame {frame_count}/{total_frames}")
|
|
|
|
| 106 |
web_output = "ldobj_final.mp4"
|
| 107 |
os.system(f"ffmpeg -y -i {raw_output} -c:v libx264 -preset fast -pix_fmt yuv420p -movflags +faststart {web_output}")
|
| 108 |
|
|
|
|
| 109 |
process_time = time.time() - start_time
|
| 110 |
+
avg_fps = frame_count / process_time if process_time > 0 else 0
|
| 111 |
|
| 112 |
telemetry_report = (
|
| 113 |
f"✅ Analysis Complete\n"
|
|
|
|
| 129 |
.sub-title { text-align: center; color: #888; margin-top: 0px; margin-bottom: 30px; }
|
| 130 |
"""
|
| 131 |
|
| 132 |
+
# IMPORTANT: No theme/css parameters inside gr.Blocks() for Gradio 6.0!
|
| 133 |
+
with gr.Blocks() as app:
|
| 134 |
gr.HTML("<h1 class='glow-title'>🛡️ LDobj ADAS Command Center</h1>")
|
| 135 |
gr.HTML("<h3 class='sub-title'>Advanced Driver Assistance System • Neural Lane Tracking</h3>")
|
| 136 |
|
| 137 |
with gr.Group():
|
| 138 |
with gr.Row():
|
|
|
|
| 139 |
with gr.Column(scale=4):
|
| 140 |
gr.Markdown("### 1. Input Source")
|
| 141 |
video_in = gr.Video(label="Dashcam Feed", elem_id="video-in")
|
|
|
|
| 149 |
|
| 150 |
run_btn = gr.Button("INITIALIZE SCAN", variant="primary", size="lg")
|
| 151 |
|
|
|
|
| 152 |
with gr.Column(scale=5):
|
| 153 |
gr.Markdown("### Live Output Feed")
|
| 154 |
video_out = gr.Video(label="LDobj Processed Feed", interactive=False, autoplay=True, elem_id="video-out")
|
|
|
|
| 163 |
)
|
| 164 |
|
| 165 |
if __name__ == "__main__":
|
| 166 |
+
# IMPORTANT: Theme and CSS MUST go inside the launch method!
|
| 167 |
+
# Using 'Glass' theme which is natively supported and looks fantastic in Dark Mode.
|
| 168 |
+
app.launch(
|
| 169 |
+
theme=gr.themes.Glass(primary_hue="red"),
|
| 170 |
+
css=custom_css,
|
| 171 |
+
footer_links=[] # Hides the Gradio footer cleanly
|
| 172 |
+
)
|