Spaces:
Sleeping
Sleeping
import dash | |
from dash import html, dcc | |
import pandas as pd | |
import plotly.graph_objects as go | |
import random | |
# Config | |
AREAS = ['Kurnool', 'Hyderabad', 'Ballari', 'Gadwal'] | |
POLES_PER_AREA = 12 | |
ALERT_LEVELS = ['Green', 'Yellow', 'Red'] | |
def simulate_poles(): | |
poles = [] | |
for area in AREAS: | |
for i in range(1, POLES_PER_AREA + 1): | |
solar = round(random.uniform(3.0, 7.5), 2) | |
wind = round(random.uniform(0.5, 2.0), 2) | |
tilt = round(random.uniform(0, 10), 2) | |
vibration = round(random.uniform(0, 3), 2) | |
camera_status = random.choice(['Online', 'Offline']) | |
total_power = solar + wind | |
required_power = 6.5 | |
alert = 'Green' | |
if total_power < 4 or tilt > 6 or vibration > 2.5: | |
alert = 'Yellow' | |
if total_power < 3 or tilt > 8 or vibration > 2.8: | |
alert = 'Red' | |
poles.append({ | |
'Area': area, | |
'Pole': f'P{i}', | |
'Solar (kWh)': solar, | |
'Wind (kWh)': wind, | |
'Power Total': total_power, | |
'Tilt (°)': tilt, | |
'Vibration (g)': vibration, | |
'Camera': camera_status, | |
'Alert': alert | |
}) | |
return pd.DataFrame(poles) | |
df = simulate_poles() | |
# Convert alerts to numeric levels for color scale | |
alert_map = {'Green': 1, 'Yellow': 2, 'Red': 3} | |
df['AlertLevel'] = df['Alert'].map(alert_map) | |
def create_alert_heatmap(df): | |
pivot_df = df.pivot(index='Area', columns='Pole', values='AlertLevel') | |
color_scale = [ | |
[0, "green"], | |
[0.5, "yellow"], | |
[1.0, "red"] | |
] | |
fig = go.Figure(data=go.Heatmap( | |
z=pivot_df.values, | |
x=pivot_df.columns, | |
y=pivot_df.index, | |
colorscale=color_scale, | |
zmin=1, | |
zmax=3, | |
showscale=False, | |
hovertemplate="Pole: %{x}<br>Area: %{y}<br>Alert Level: %{z}<extra></extra>" | |
)) | |
fig.update_layout(title="Smart Pole Alert Heatmap", height=500) | |
return fig | |
app = dash.Dash(__name__) | |
server = app.server # Required for Hugging Face | |
app.layout = html.Div([ | |
html.H1("Vedavathi Smart Pole Monitoring", style={"textAlign": "center"}), | |
dcc.Graph(figure=create_alert_heatmap(df)), | |
html.Div([ | |
html.H3("🚨 Red Alert Poles", style={"color": "red", "textAlign": "center"}), | |
html.Div([ | |
html.Span(f"{row['Area']} - {row['Pole']}", style={ | |
"animation": "blinker 1s linear infinite", | |
"color": "red", | |
"fontWeight": "bold", | |
"fontSize": "18px", | |
"margin": "8px", | |
"display": "inline-block" | |
}) | |
for _, row in df[df["Alert"] == "Red"].iterrows() | |
], style={"textAlign": "center"}) | |
]), | |
dcc.Markdown(''' | |
<style> | |
@keyframes blinker { | |
50% { opacity: 0; } | |
} | |
</style> | |
''', dangerously_allow_html=True) | |
]) | |
if __name__ == "__main__": | |
app.run_server(debug=False, host="0.0.0.0", port=7860) | |