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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -17
app.py CHANGED
@@ -52,7 +52,7 @@ from pathlib import Path
52
 
53
  # Resolve repository root relative to this file (streamlit_app/app.py)
54
  THIS_FILE = Path(__file__).resolve()
55
- REPO_ROOT = THIS_FILE.parent # repo/
56
  SAVED_MODELS_DIR = REPO_ROOT / "saved_models"
57
  YOLO_RUNS_DIR = REPO_ROOT / "yolo_runs"
58
  SMARTVISION_METRICS_DIR = REPO_ROOT / "smartvision_metrics"
@@ -287,7 +287,6 @@ def build_efficientnetb0_model():
287
  include_top=False,
288
  weights="imagenet"
289
  )
290
-
291
  x = base_model(x, training=False)
292
 
293
  x = layers.GlobalAveragePooling2D(name="gap")(x)
@@ -598,7 +597,7 @@ of **25 COCO classes**. It brings together:
598
  cols = st.columns(min(3, len(imgs)))
599
  for i, img_path in enumerate(imgs[:3]):
600
  with cols[i]:
601
- st.image(img_path, caption=os.path.basename(img_path), use_container_width=False)
602
  else:
603
  st.info("No sample images found in `inference_outputs/` yet.")
604
  else:
@@ -621,7 +620,7 @@ The app will run **all 4 CNN models** and show **top-5 predictions** per model.
621
 
622
  if uploaded_file is not None:
623
  pil_img = read_image_file(uploaded_file)
624
- st.image(pil_img, caption="Uploaded image", use_container_width=False)
625
 
626
  with st.spinner("Loading classification models..."):
627
  cls_models = load_classification_models()
@@ -661,16 +660,23 @@ YOLOv8 will detect all objects and optionally verify them with the best classifi
661
  """
662
  )
663
 
664
- conf_th = st.slider("Confidence threshold", 0.1, 0.9, 0.5, 0.05)
665
- use_classifier = st.checkbox("Use ResNet50 classifier verification on crops", value=True)
666
 
667
- uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
668
 
 
 
 
 
 
 
 
 
 
 
669
  if uploaded_file is not None:
670
  pil_img = read_image_file(uploaded_file)
671
 
672
  # ❌ REMOVE THIS (caused duplicate)
673
- # st.image(pil_img, caption="Uploaded image", use_container_width=False)
674
 
675
  with st.spinner("Loading YOLO model..."):
676
  yolo_model = load_yolo_model()
@@ -703,10 +709,10 @@ YOLOv8 will detect all objects and optionally verify them with the best classifi
703
  col1, col2 = st.columns(2)
704
 
705
  with col1:
706
- st.image(pil_img, caption="Uploaded Image", use_container_width=True)
707
 
708
  with col2:
709
- st.image(result["annotated_image"], caption="Detected Result", use_container_width=True)
710
 
711
  st.write(f"YOLO inference time: {result['yolo_inference_time_sec']*1000:.1f} ms")
712
  st.write(f"Number of detections: {len(result['detections'])}")
@@ -723,7 +729,7 @@ YOLOv8 will detect all objects and optionally verify them with the best classifi
723
  }
724
  for det in result["detections"]
725
  ])
726
- st.dataframe(df_det, use_container_width=False)
727
 
728
  # ------------------------------------------------------------
729
  # PAGE 4 – MODEL PERFORMANCE
@@ -737,24 +743,24 @@ elif page == "πŸ“Š Model Performance":
737
  if df_cls.empty:
738
  st.info("No classification metrics found yet in `smartvision_metrics/`.")
739
  else:
740
- st.dataframe(df_cls, use_container_width=False)
741
 
742
  col1, col2 = st.columns(2)
743
  with col1:
744
  st.bar_chart(
745
  df_cls.set_index("Model")["Accuracy"],
746
- use_container_width=True,
747
  )
748
  with col2:
749
  st.bar_chart(
750
  df_cls.set_index("Model")["F1 (weighted)"],
751
- use_container_width=True,
752
  )
753
 
754
  st.markdown("#### Inference Speed (images/sec)")
755
  st.bar_chart(
756
  df_cls.set_index("Model")["Images/sec"],
757
- use_container_width=True,
758
  )
759
 
760
  # --- YOLO metrics ---
@@ -785,7 +791,7 @@ elif page == "πŸ“Š Model Performance":
785
  ]
786
  if imgs:
787
  for img in sorted(imgs):
788
- st.image(img, caption=os.path.basename(img), use_container_width=True)
789
  else:
790
  st.info("No comparison plots found in `smartvision_metrics/comparison_plots/`.")
791
  else:
@@ -825,7 +831,7 @@ from your webcam and run YOLOv8 detection on it.
825
  conf_threshold=conf_th,
826
  )
827
 
828
- st.image(result["annotated_image"], caption="Detections", use_container_width=False)
829
  st.write(f"YOLO inference time: {result['yolo_inference_time_sec']*1000:.1f} ms")
830
  st.write(f"Number of detections: {len(result['detections'])}")
831
 
@@ -836,6 +842,7 @@ from your webcam and run YOLOv8 detection on it.
836
  elif page == "ℹ️ About":
837
  st.subheader("About SmartVision AI")
838
 
 
839
  st.markdown(
840
  """
841
  **Dataset:**
 
52
 
53
  # Resolve repository root relative to this file (streamlit_app/app.py)
54
  THIS_FILE = Path(__file__).resolve()
55
+ REPO_ROOT = THIS_FILE.parent.parent # repo/
56
  SAVED_MODELS_DIR = REPO_ROOT / "saved_models"
57
  YOLO_RUNS_DIR = REPO_ROOT / "yolo_runs"
58
  SMARTVISION_METRICS_DIR = REPO_ROOT / "smartvision_metrics"
 
287
  include_top=False,
288
  weights="imagenet"
289
  )
 
290
  x = base_model(x, training=False)
291
 
292
  x = layers.GlobalAveragePooling2D(name="gap")(x)
 
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
 
 
842
  elif page == "ℹ️ About":
843
  st.subheader("About SmartVision AI")
844
 
845
+
846
  st.markdown(
847
  """
848
  **Dataset:**