Spaces:
Sleeping
Sleeping
| """ | |
| Streamlit Sidebar Components | |
| Semua widget yang ada di sidebar Streamlit dikelola di sini, | |
| supaya app.py tetap bersih dan fokus ke logic utama. | |
| """ | |
| import streamlit as st | |
| def render_sidebar(): | |
| """ | |
| Render sidebar dan return konfigurasi yang dipilih user. | |
| Returns: | |
| dict berisi semua setting dari sidebar: | |
| - uploaded_video: UploadedFile atau None | |
| - confidence: float | |
| - counting_mode: str ("Virtual Line" atau "Polygon Region") | |
| - line_position: float (0.0 - 1.0) | |
| - show_trajectories: bool | |
| """ | |
| st.sidebar.title("Konfigurasi") | |
| st.sidebar.markdown("---") | |
| # upload video | |
| st.sidebar.subheader("Input Video") | |
| uploaded_video = st.sidebar.file_uploader( | |
| "Upload video (.mp4 / .avi)", | |
| type=["mp4", "avi", "mov"], | |
| help="Pilih file video yang berisi rekaman lalu lintas kendaraan" | |
| ) | |
| st.sidebar.markdown("---") | |
| # model settings | |
| st.sidebar.subheader("Model Settings") | |
| confidence = st.sidebar.slider( | |
| "Confidence Threshold", | |
| min_value=0.1, | |
| max_value=0.9, | |
| value=0.5, | |
| step=0.05, | |
| help="Minimum confidence score untuk deteksi. Nilai lebih tinggi = lebih ketat" | |
| ) | |
| st.sidebar.markdown("---") | |
| # counting settings | |
| st.sidebar.subheader("Counting Mode") | |
| counting_mode = st.sidebar.radio( | |
| "Pilih metode counting", | |
| options=["Virtual Line", "Polygon Region"], | |
| index=0, | |
| help="Virtual Line: hitung kendaraan yang melewati garis. " | |
| "Polygon Region: hitung kendaraan yang masuk area tertentu." | |
| ) | |
| line_position = 0.5 | |
| if counting_mode == "Virtual Line": | |
| line_position = st.sidebar.slider( | |
| "Posisi Garis (dari atas)", | |
| min_value=0.1, | |
| max_value=0.9, | |
| value=0.5, | |
| step=0.05, | |
| help="Posisi garis virtual sebagai persentase dari tinggi frame" | |
| ) | |
| st.sidebar.markdown("---") | |
| # display settings | |
| st.sidebar.subheader("Display") | |
| show_trajectories = st.sidebar.checkbox( | |
| "Tampilkan Trajectory", | |
| value=True, | |
| help="Tampilkan jejak pergerakan kendaraan" | |
| ) | |
| st.sidebar.markdown("---") | |
| # info section | |
| st.sidebar.subheader("Tentang") | |
| st.sidebar.info( | |
| "Vehicle Detection & Counting menggunakan RT-DETR + ByteTrack. " | |
| "Proyek portofolio AI Engineer untuk Computer Vision." | |
| ) | |
| st.sidebar.markdown( | |
| "**Tech Stack:** RT-DETR, ByteTrack, OpenCV, Streamlit" | |
| ) | |
| config = { | |
| "uploaded_video": uploaded_video, | |
| "confidence": confidence, | |
| "counting_mode": counting_mode, | |
| "line_position": line_position, | |
| "show_trajectories": show_trajectories | |
| } | |
| return config | |