yogesh-venkat commited on
Commit
14d5ddc
Β·
verified Β·
1 Parent(s): 609eddb

Update streamlit_app/streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app/streamlit_app.py +22 -15
streamlit_app/streamlit_app.py CHANGED
@@ -597,7 +597,7 @@ of **25 COCO classes**. It brings together:
597
  cols = st.columns(min(3, len(imgs)))
598
  for i, img_path in enumerate(imgs[:3]):
599
  with cols[i]:
600
- st.image(img_path, caption=os.path.basename(img_path), use_container_width=False)
601
  else:
602
  st.info("No sample images found in `inference_outputs/` yet.")
603
  else:
@@ -620,7 +620,7 @@ The app will run **all 4 CNN models** and show **top-5 predictions** per model.
620
 
621
  if uploaded_file is not None:
622
  pil_img = read_image_file(uploaded_file)
623
- st.image(pil_img, caption="Uploaded image", use_container_width=False)
624
 
625
  with st.spinner("Loading classification models..."):
626
  cls_models = load_classification_models()
@@ -660,16 +660,23 @@ YOLOv8 will detect all objects and optionally verify them with the best classifi
660
  """
661
  )
662
 
663
- conf_th = st.slider("Confidence threshold", 0.1, 0.9, 0.5, 0.05)
664
- use_classifier = st.checkbox("Use ResNet50 classifier verification on crops", value=True)
665
 
666
- uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
667
 
 
 
 
 
 
 
 
 
 
 
668
  if uploaded_file is not None:
669
  pil_img = read_image_file(uploaded_file)
670
 
671
  # ❌ REMOVE THIS (caused duplicate)
672
- # st.image(pil_img, caption="Uploaded image", use_container_width=False)
673
 
674
  with st.spinner("Loading YOLO model..."):
675
  yolo_model = load_yolo_model()
@@ -702,10 +709,10 @@ YOLOv8 will detect all objects and optionally verify them with the best classifi
702
  col1, col2 = st.columns(2)
703
 
704
  with col1:
705
- st.image(pil_img, caption="Uploaded Image", use_container_width=True)
706
 
707
  with col2:
708
- st.image(result["annotated_image"], caption="Detected Result", use_container_width=True)
709
 
710
  st.write(f"YOLO inference time: {result['yolo_inference_time_sec']*1000:.1f} ms")
711
  st.write(f"Number of detections: {len(result['detections'])}")
@@ -722,7 +729,7 @@ YOLOv8 will detect all objects and optionally verify them with the best classifi
722
  }
723
  for det in result["detections"]
724
  ])
725
- st.dataframe(df_det, use_container_width=False)
726
 
727
  # ------------------------------------------------------------
728
  # PAGE 4 – MODEL PERFORMANCE
@@ -736,24 +743,24 @@ elif page == "πŸ“Š Model Performance":
736
  if df_cls.empty:
737
  st.info("No classification metrics found yet in `smartvision_metrics/`.")
738
  else:
739
- st.dataframe(df_cls, use_container_width=False)
740
 
741
  col1, col2 = st.columns(2)
742
  with col1:
743
  st.bar_chart(
744
  df_cls.set_index("Model")["Accuracy"],
745
- use_container_width=True,
746
  )
747
  with col2:
748
  st.bar_chart(
749
  df_cls.set_index("Model")["F1 (weighted)"],
750
- use_container_width=True,
751
  )
752
 
753
  st.markdown("#### Inference Speed (images/sec)")
754
  st.bar_chart(
755
  df_cls.set_index("Model")["Images/sec"],
756
- use_container_width=True,
757
  )
758
 
759
  # --- YOLO metrics ---
@@ -784,7 +791,7 @@ elif page == "πŸ“Š Model Performance":
784
  ]
785
  if imgs:
786
  for img in sorted(imgs):
787
- st.image(img, caption=os.path.basename(img), use_container_width=True)
788
  else:
789
  st.info("No comparison plots found in `smartvision_metrics/comparison_plots/`.")
790
  else:
@@ -824,7 +831,7 @@ from your webcam and run YOLOv8 detection on it.
824
  conf_threshold=conf_th,
825
  )
826
 
827
- st.image(result["annotated_image"], caption="Detections", use_container_width=False)
828
  st.write(f"YOLO inference time: {result['yolo_inference_time_sec']*1000:.1f} ms")
829
  st.write(f"Number of detections: {len(result['detections'])}")
830
 
 
597
  cols = st.columns(min(3, len(imgs)))
598
  for i, img_path in enumerate(imgs[:3]):
599
  with cols[i]:
600
+ st.image(img_path, caption=os.path.basename(img_path), width='content')
601
  else:
602
  st.info("No sample images found in `inference_outputs/` yet.")
603
  else:
 
620
 
621
  if uploaded_file is not None:
622
  pil_img = read_image_file(uploaded_file)
623
+ st.image(pil_img, caption="Uploaded image", width='content')
624
 
625
  with st.spinner("Loading classification models..."):
626
  cls_models = load_classification_models()
 
660
  """
661
  )
662
 
 
 
663
 
 
664
 
665
+
666
+ with st.form("detection_form"):
667
+ conf_th = st.slider("Confidence threshold", 0.1, 0.9, 0.5, 0.05)
668
+ use_classifier = st.checkbox("Use ResNet50 classifier verification", value=True)
669
+
670
+ # 2. Add a Submit button
671
+ submitted = st.form_submit_button("Run Detection")
672
+
673
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
674
+
675
  if uploaded_file is not None:
676
  pil_img = read_image_file(uploaded_file)
677
 
678
  # ❌ REMOVE THIS (caused duplicate)
679
+ # st.image(pil_img, caption="Uploaded image", width='content')
680
 
681
  with st.spinner("Loading YOLO model..."):
682
  yolo_model = load_yolo_model()
 
709
  col1, col2 = st.columns(2)
710
 
711
  with col1:
712
+ st.image(pil_img, caption="Uploaded Image", width='stretch')
713
 
714
  with col2:
715
+ st.image(result["annotated_image"], caption="Detected Result", width='stretch')
716
 
717
  st.write(f"YOLO inference time: {result['yolo_inference_time_sec']*1000:.1f} ms")
718
  st.write(f"Number of detections: {len(result['detections'])}")
 
729
  }
730
  for det in result["detections"]
731
  ])
732
+ st.dataframe(df_det, width='content')
733
 
734
  # ------------------------------------------------------------
735
  # PAGE 4 – MODEL PERFORMANCE
 
743
  if df_cls.empty:
744
  st.info("No classification metrics found yet in `smartvision_metrics/`.")
745
  else:
746
+ st.dataframe(df_cls, width='content')
747
 
748
  col1, col2 = st.columns(2)
749
  with col1:
750
  st.bar_chart(
751
  df_cls.set_index("Model")["Accuracy"],
752
+ width='stretch',
753
  )
754
  with col2:
755
  st.bar_chart(
756
  df_cls.set_index("Model")["F1 (weighted)"],
757
+ width='stretch',
758
  )
759
 
760
  st.markdown("#### Inference Speed (images/sec)")
761
  st.bar_chart(
762
  df_cls.set_index("Model")["Images/sec"],
763
+ width='stretch',
764
  )
765
 
766
  # --- YOLO metrics ---
 
791
  ]
792
  if imgs:
793
  for img in sorted(imgs):
794
+ st.image(img, caption=os.path.basename(img), width='stretch')
795
  else:
796
  st.info("No comparison plots found in `smartvision_metrics/comparison_plots/`.")
797
  else:
 
831
  conf_threshold=conf_th,
832
  )
833
 
834
+ st.image(result["annotated_image"], caption="Detections", width='content')
835
  st.write(f"YOLO inference time: {result['yolo_inference_time_sec']*1000:.1f} ms")
836
  st.write(f"Number of detections: {len(result['detections'])}")
837