Download app.py from DP1110/STREETLIGHTING: direct link, hf CLI and curl.
- Browser
- Download file 9.02 kB
-
https://huggingface.co/DP1110/STREETLIGHTING/resolve/main/app.py
- Command line
-
hf download hf://DP1110/STREETLIGHTING/app.py
-
curl -L -o app.py https://huggingface.co/DP1110/STREETLIGHTING/resolve/main/app.py
9.02 kB
| # ============================================================ | |
| # LumiAI - LIVE AI STREET LIGHTING DASHBOARD | |
| # ============================================================ | |
| import streamlit as st | |
| import pandas as pd | |
| import numpy as np | |
| import plotly.graph_objects as go | |
| from datetime import datetime | |
| import time | |
| # ============================================================ | |
| # PAGE CONFIGURATION | |
| # ============================================================ | |
| st.set_page_config( | |
| page_title="LumiAI Smart Street Lighting", | |
| page_icon="π‘", | |
| layout="wide" | |
| ) | |
| # ============================================================ | |
| # TITLE | |
| # ============================================================ | |
| st.title("π‘ LumiAI") | |
| st.subheader( | |
| "AI-Based Adaptive Smart Street Lighting " | |
| "for Energy Optimization" | |
| ) | |
| st.markdown( | |
| "### YOLO + LSTM + Q-Learning" | |
| ) | |
| # ============================================================ | |
| # SIDEBAR | |
| # ============================================================ | |
| st.sidebar.header("System Control") | |
| road = st.sidebar.selectbox( | |
| "Select Road", | |
| [ | |
| "Road A", | |
| "Road B", | |
| "Road C", | |
| "Road D" | |
| ] | |
| ) | |
| auto_refresh = st.sidebar.checkbox( | |
| "Live Refresh", | |
| value=True | |
| ) | |
| # ============================================================ | |
| # SIMULATED LIVE YOLO DATA | |
| # ============================================================ | |
| # In final system these values will come from YOLO | |
| vehicle_count = np.random.randint( | |
| 5, | |
| 100 | |
| ) | |
| pedestrian_count = np.random.randint( | |
| 0, | |
| 20 | |
| ) | |
| # ============================================================ | |
| # TRAFFIC CLASSIFICATION | |
| # ============================================================ | |
| if vehicle_count < 20: | |
| traffic_level = "LOW" | |
| elif vehicle_count < 60: | |
| traffic_level = "MEDIUM" | |
| else: | |
| traffic_level = "HIGH" | |
| # ============================================================ | |
| # LSTM TRAFFIC PREDICTION | |
| # ============================================================ | |
| # Demonstration prediction | |
| # Replace this with actual LSTM prediction | |
| predicted_traffic = int( | |
| vehicle_count | |
| + np.random.randint(-5, 15) | |
| ) | |
| predicted_traffic = max( | |
| 0, | |
| predicted_traffic | |
| ) | |
| # ============================================================ | |
| # Q-LEARNING OPTIMAL BRIGHTNESS | |
| # ============================================================ | |
| if predicted_traffic >= 60: | |
| brightness = 100 | |
| elif predicted_traffic >= 20: | |
| brightness = 70 | |
| elif predicted_traffic > 0: | |
| brightness = 50 | |
| else: | |
| brightness = 30 | |
| # ============================================================ | |
| # ENERGY MODEL | |
| # ============================================================ | |
| MAX_POWER = 100 # Watts | |
| power = ( | |
| MAX_POWER | |
| * brightness | |
| / 100 | |
| ) | |
| # 15-minute energy consumption | |
| energy = ( | |
| power | |
| * 0.25 | |
| / 1000 | |
| ) | |
| # Conventional energy | |
| conventional_energy = ( | |
| MAX_POWER | |
| * 0.25 | |
| / 1000 | |
| ) | |
| energy_saved = ( | |
| conventional_energy | |
| - energy | |
| ) | |
| saving_percentage = ( | |
| energy_saved | |
| / conventional_energy | |
| ) * 100 | |
| # ============================================================ | |
| # CURRENT TIME | |
| # ============================================================ | |
| current_time = datetime.now().strftime( | |
| "%H:%M:%S" | |
| ) | |
| # ============================================================ | |
| # TOP METRICS | |
| # ============================================================ | |
| col1, col2, col3, col4, col5 = st.columns(5) | |
| with col1: | |
| st.metric( | |
| "π Vehicles", | |
| vehicle_count | |
| ) | |
| with col2: | |
| st.metric( | |
| "πΆ Pedestrians", | |
| pedestrian_count | |
| ) | |
| with col3: | |
| st.metric( | |
| "π Traffic", | |
| traffic_level | |
| ) | |
| with col4: | |
| st.metric( | |
| "π‘ Brightness", | |
| f"{brightness}%" | |
| ) | |
| with col5: | |
| st.metric( | |
| "β‘ Energy Saving", | |
| f"{saving_percentage:.1f}%" | |
| ) | |
| st.divider() | |
| # ============================================================ | |
| # SYSTEM STATUS | |
| # ============================================================ | |
| col1, col2, col3 = st.columns(3) | |
| with col1: | |
| st.success( | |
| "π’ AI SYSTEM ACTIVE" | |
| ) | |
| with col2: | |
| st.info( | |
| f"π Last Update: {current_time}" | |
| ) | |
| with col3: | |
| st.success( | |
| f"π {road}" | |
| ) | |
| # ============================================================ | |
| # TRAFFIC + PREDICTION | |
| # ============================================================ | |
| st.header("π¦ Traffic Intelligence") | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.subheader( | |
| "Current vs Predicted Traffic" | |
| ) | |
| traffic_data = pd.DataFrame({ | |
| "Time": [ | |
| "Now", | |
| "+15 min" | |
| ], | |
| "Vehicles": [ | |
| vehicle_count, | |
| predicted_traffic | |
| ] | |
| }) | |
| fig = go.Figure() | |
| fig.add_trace( | |
| go.Bar( | |
| x=traffic_data["Time"], | |
| y=traffic_data["Vehicles"], | |
| name="Vehicles" | |
| ) | |
| ) | |
| fig.update_layout( | |
| yaxis_title="Vehicle Count", | |
| xaxis_title="Time", | |
| height=350 | |
| ) | |
| st.plotly_chart( | |
| fig, | |
| use_container_width=True | |
| ) | |
| with col2: | |
| st.subheader( | |
| "AI Lighting Decision" | |
| ) | |
| lighting_data = pd.DataFrame({ | |
| "Parameter": [ | |
| "Traffic", | |
| "Predicted Traffic", | |
| "Brightness", | |
| "Power" | |
| ], | |
| "Value": [ | |
| vehicle_count, | |
| predicted_traffic, | |
| f"{brightness}%", | |
| f"{power:.1f} W" | |
| ] | |
| }) | |
| st.table( | |
| lighting_data | |
| ) | |
| # ============================================================ | |
| # BRIGHTNESS GAUGE | |
| # ============================================================ | |
| st.header("π‘ Adaptive Lighting") | |
| fig = go.Figure( | |
| go.Indicator( | |
| mode="gauge+number", | |
| value=brightness, | |
| title={ | |
| "text": | |
| "Optimal Brightness (%)" | |
| }, | |
| gauge={ | |
| "axis": { | |
| "range": [0, 100] | |
| } | |
| } | |
| ) | |
| ) | |
| fig.update_layout( | |
| height=350 | |
| ) | |
| st.plotly_chart( | |
| fig, | |
| use_container_width=True | |
| ) | |
| # ============================================================ | |
| # ENERGY ANALYTICS | |
| # ============================================================ | |
| st.header("β‘ Energy Optimization") | |
| col1, col2, col3 = st.columns(3) | |
| with col1: | |
| st.metric( | |
| "Conventional", | |
| f"{conventional_energy:.4f} kWh" | |
| ) | |
| with col2: | |
| st.metric( | |
| "LumiAI", | |
| f"{energy:.4f} kWh" | |
| ) | |
| with col3: | |
| st.metric( | |
| "Saved", | |
| f"{energy_saved:.4f} kWh" | |
| ) | |
| # ============================================================ | |
| # ENERGY COMPARISON GRAPH | |
| # ============================================================ | |
| energy_df = pd.DataFrame({ | |
| "System": [ | |
| "Conventional", | |
| "LumiAI" | |
| ], | |
| "Energy": [ | |
| conventional_energy, | |
| energy | |
| ] | |
| }) | |
| fig = go.Figure() | |
| fig.add_trace( | |
| go.Bar( | |
| x=energy_df["System"], | |
| y=energy_df["Energy"], | |
| name="Energy" | |
| ) | |
| ) | |
| fig.update_layout( | |
| title="Energy Consumption Comparison", | |
| yaxis_title="Energy (kWh)", | |
| height=400 | |
| ) | |
| st.plotly_chart( | |
| fig, | |
| use_container_width=True | |
| ) | |
| # ============================================================ | |
| # AI DECISION EXPLANATION | |
| # ============================================================ | |
| st.header("π§ AI Decision") | |
| if brightness == 100: | |
| st.error( | |
| "HIGH TRAFFIC β Maximum brightness selected " | |
| "for safety." | |
| ) | |
| elif brightness == 70: | |
| st.warning( | |
| "MEDIUM TRAFFIC β 70% brightness selected." | |
| ) | |
| elif brightness == 50: | |
| st.info( | |
| "LOW TRAFFIC β 50% brightness selected." | |
| ) | |
| else: | |
| st.success( | |
| "VERY LOW TRAFFIC β Minimum safe brightness." | |
| ) | |
| # ============================================================ | |
| # ROAD STATUS | |
| # ============================================================ | |
| st.header("πΊοΈ Road Network Status") | |
| road_data = pd.DataFrame({ | |
| "Road": [ | |
| "Road A", | |
| "Road B", | |
| "Road C", | |
| "Road D" | |
| ], | |
| "Traffic": [ | |
| np.random.randint(10, 100), | |
| np.random.randint(10, 100), | |
| np.random.randint(10, 100), | |
| np.random.randint(10, 100) | |
| ] | |
| }) | |
| road_data["Brightness"] = road_data[ | |
| "Traffic" | |
| ].apply( | |
| lambda x: | |
| 100 if x >= 60 | |
| else 70 if x >= 20 | |
| else 50 | |
| ) | |
| st.dataframe( | |
| road_data, | |
| use_container_width=True | |
| ) | |
| # ============================================================ | |
| # FOOTER | |
| # ============================================================ | |
| st.divider() | |
| st.caption( | |
| "LumiAI | YOLO + LSTM + Q-Learning | " | |
| "AI-Based Energy Optimization" | |
| ) | |
| # ============================================================ | |
| # AUTO REFRESH | |
| # ============================================================ | |
| if auto_refresh: | |
| time.sleep(3) | |
| st.rerun() |