import streamlit as st import cv2 import numpy as np from queue_monitor import QueueMonitor from llm_analyzer import LogAnalyzer import json import pandas as pd st.set_page_config(page_title="AI Queue Management", layout="wide") st.title("AI Queue Management for CCTV and YOLO") # Sidebar for configuration st.sidebar.header("Configuration") confidence = st.sidebar.slider("Confidence Threshold", 0.0, 1.0, 0.3) @st.cache_resource def load_monitor(conf): return QueueMonitor(confidence=conf) @st.cache_resource def load_analyzer(): return LogAnalyzer() monitor = load_monitor(confidence) # Default zone default_polygon = np.array([[100, 100], [1100, 100], [1100, 600], [100, 600]]) monitor.setup_zones([default_polygon]) tab1, tab2, tab3 = st.tabs(["Vision Monitoring", "AI Log Analysis", "Use Cases"]) with tab1: st.header("Vision Monitoring") uploaded_file = st.file_uploader("Upload CCTV Video", type=['mp4', 'avi', 'mov']) if uploaded_file is not None: # Save uploaded file temporarily with open("temp_video.mp4", "wb") as f: f.write(uploaded_file.read()) cap = cv2.VideoCapture("temp_video.mp4") st_frame = st.empty() if st.button("Start Processing"): while cap.isOpened(): ret, frame = cap.read() if not ret: break annotated, stats = monitor.process_frame(frame) st_frame.image(cv2.cvtColor(annotated, cv2.COLOR_BGR2RGB)) # Display stats in a table st.write("Current Zone Stats:") st.table(pd.DataFrame(stats)) cap.release() with tab2: st.header("AI Log Analysis") st.write("Analyze queue performance logs using Qwen-2.5-1.5B-Instruct.") sample_log = { "date": "2026-01-24", "branch": "SBI Jabalpur", "avg_wait_time_sec": 420, "max_wait_time_sec": 980, "customers_served": 134, "counter_1_avg_service": 180, "counter_2_avg_service": 310, "peak_hour": "12:00-13:00", "queue_overflow_events": 5 } log_input = st.text_area("Log Data (JSON)", value=json.dumps(sample_log, indent=2), height=250) if st.button("Analyze with AI"): with st.spinner("LLM is thinking..."): try: analyzer = load_analyzer() log_data = json.loads(log_input) analysis = analyzer.analyze_logs(log_data) st.markdown("### AI Insights & Recommendations") st.write(analysis) except Exception as e: st.error(f"Error: {str(e)}") with tab3: st.header("Expanded Use Cases") use_cases = { "Retail Heatmap": "Track customer movement and dwell time in specific aisles.", "Bank Efficiency": "Monitor counter service times and optimize teller allocation.", "Airport Security": "Predict queue growth and manage security lane staffing.", "Hospital ER": "Ensure patients are seen within target wait times.", "Smart Parking": "Monitor parking bay occupancy and turnover rates.", "Safety Zones": "Alert security if someone enters or lingers in restricted areas." } for title, desc in use_cases.items(): st.subheader(title) st.write(desc)