fouadmahmoud283-ai commited on
Commit
7f27589
Β·
1 Parent(s): 9dad6c1

fixing camera n1235

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +89 -4
src/streamlit_app.py CHANGED
@@ -180,7 +180,6 @@ def load_model(confidence_threshold=0.5):
180
  # If no local model, load pretrained YOLOv5s
181
  if model is None:
182
  model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True, trust_repo=True)
183
- st.warning("⚠️ Using pretrained YOLOv5s model. For best wheelchair navigation, upload your trained model.")
184
 
185
  model.conf = confidence_threshold
186
  model.iou = 0.45
@@ -363,7 +362,7 @@ def main():
363
  st.markdown(f'<span style="color: {color}; font-weight: bold;">●</span> {class_name.title()}', unsafe_allow_html=True)
364
 
365
  # Main content tabs
366
- tab1, tab2, tab3, tab4 = st.tabs(["πŸ“Έ Live Detection", "πŸ“Š Analytics", "ℹ️ About", "πŸš€ Deployment"])
367
 
368
  with tab1:
369
  col1, col2 = st.columns([2, 1])
@@ -493,6 +492,92 @@ def main():
493
  st.dataframe(display_df, use_container_width=True)
494
 
495
  with tab2:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
496
  st.markdown("### πŸ“Š Detection Analytics")
497
 
498
  if uploaded_file is not None and 'detections' in locals() and detections is not None:
@@ -527,7 +612,7 @@ def main():
527
  else:
528
  st.info("πŸ“Έ Upload an image in the 'Live Detection' tab to see analytics")
529
 
530
- with tab3:
531
  st.markdown("### ℹ️ About This System")
532
 
533
  col1, col2 = st.columns([2, 1])
@@ -623,7 +708,7 @@ def main():
623
  - Power Supply
624
  """)
625
 
626
- with tab4:
627
  st.markdown("### πŸš€ Deployment Information")
628
 
629
  col1, col2 = st.columns(2)
 
180
  # If no local model, load pretrained YOLOv5s
181
  if model is None:
182
  model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True, trust_repo=True)
 
183
 
184
  model.conf = confidence_threshold
185
  model.iou = 0.45
 
362
  st.markdown(f'<span style="color: {color}; font-weight: bold;">●</span> {class_name.title()}', unsafe_allow_html=True)
363
 
364
  # Main content tabs
365
+ tab1, tab2, tab3, tab4, tab5 = st.tabs(["πŸ“Έ Live Detection", "πŸ“Ή Realtime Camera", "πŸ“Š Analytics", "ℹ️ About", "πŸš€ Deployment"])
366
 
367
  with tab1:
368
  col1, col2 = st.columns([2, 1])
 
492
  st.dataframe(display_df, use_container_width=True)
493
 
494
  with tab2:
495
+ st.markdown("### πŸ“Ή Realtime Camera Detection")
496
+ st.caption("Allow camera access, then take a photo to run detection.")
497
+
498
+ camera_image = st.camera_input(
499
+ "Capture an image",
500
+ key="camera_input"
501
+ )
502
+
503
+ if camera_image is not None:
504
+ try:
505
+ image = Image.open(camera_image)
506
+ except Exception as e:
507
+ st.error(f"Could not read camera image: {e}")
508
+ image = None
509
+
510
+ if image is not None:
511
+ col1, col2 = st.columns(2)
512
+
513
+ with col1:
514
+ st.markdown("#### πŸ“Έ Captured Image")
515
+ st.image(image, width=500)
516
+
517
+ # Load model
518
+ if st.session_state.model is None:
519
+ with st.spinner("πŸ€– Loading AI model..."):
520
+ st.session_state.model = load_model(conf_threshold)
521
+
522
+ if st.session_state.model is not None:
523
+ # Process image
524
+ with st.spinner("πŸ” Analyzing image for obstacles..."):
525
+ start_time = time.time()
526
+ rendered_img, detections, results = process_image(image, st.session_state.model, conf_threshold)
527
+ processing_time = time.time() - start_time
528
+
529
+ with col2:
530
+ st.markdown("#### 🎯 Detection Results")
531
+ if rendered_img is not None:
532
+ st.image(rendered_img, width=500)
533
+
534
+ # Generate navigation advice
535
+ advice, safety_level = get_navigation_advice(detections, image.width)
536
+
537
+ # Update safety status
538
+ st.markdown("### πŸ›‘οΈ Safety Status")
539
+ if "CRITICAL" in safety_level:
540
+ st.markdown(f'<div class="safety-alert"><strong>{safety_level}</strong></div>', unsafe_allow_html=True)
541
+ elif "CAUTION" in safety_level:
542
+ st.markdown(f'<div style="background: #fff3cd; color: #856404; padding: 1rem; border-radius: 8px; border-left: 4px solid #ffc107;"><strong>{safety_level}</strong></div>', unsafe_allow_html=True)
543
+ else:
544
+ st.markdown(f'<div class="success-alert"><strong>{safety_level}</strong></div>', unsafe_allow_html=True)
545
+
546
+ # Display navigation advice
547
+ st.markdown("### 🧭 Navigation Advice")
548
+ for advice_text in advice:
549
+ st.markdown(f'<div class="detection-box">{advice_text}</div>', unsafe_allow_html=True)
550
+
551
+ # Performance metrics
552
+ st.markdown("### ⚑ Performance Metrics")
553
+ perf_col1, perf_col2, perf_col3, perf_col4 = st.columns(4)
554
+
555
+ with perf_col1:
556
+ st.metric("⏱️ Processing Time", f"{processing_time:.2f}s")
557
+
558
+ with perf_col2:
559
+ fps = 1 / processing_time if processing_time > 0 else 0
560
+ st.metric("🎬 Estimated FPS", f"{fps:.1f}")
561
+
562
+ with perf_col3:
563
+ total_detections = len(detections) if detections is not None else 0
564
+ st.metric("πŸ” Objects Detected", total_detections)
565
+
566
+ with perf_col4:
567
+ relevant_count = len(detections) if detections is not None else 0
568
+ st.metric("🎯 Relevant Objects", relevant_count)
569
+
570
+ # Detailed detection results
571
+ if detections is not None and len(detections) > 0:
572
+ st.markdown("### πŸ“‹ Detailed Detection Results")
573
+
574
+ display_df = detections[['name', 'confidence', 'xmin', 'ymin', 'xmax', 'ymax']].copy()
575
+ display_df['confidence'] = display_df['confidence'].apply(lambda x: f"{x:.1%}")
576
+ display_df.columns = ['Object', 'Confidence', 'X Min', 'Y Min', 'X Max', 'Y Max']
577
+
578
+ st.dataframe(display_df, use_container_width=True)
579
+
580
+ with tab3:
581
  st.markdown("### πŸ“Š Detection Analytics")
582
 
583
  if uploaded_file is not None and 'detections' in locals() and detections is not None:
 
612
  else:
613
  st.info("πŸ“Έ Upload an image in the 'Live Detection' tab to see analytics")
614
 
615
+ with tab4:
616
  st.markdown("### ℹ️ About This System")
617
 
618
  col1, col2 = st.columns([2, 1])
 
708
  - Power Supply
709
  """)
710
 
711
+ with tab5:
712
  st.markdown("### πŸš€ Deployment Information")
713
 
714
  col1, col2 = st.columns(2)