Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import dash
|
2 |
+
from dash import dcc, html, dash_table
|
3 |
+
import pandas as pd
|
4 |
+
import numpy as np
|
5 |
+
import plotly.graph_objects as go
|
6 |
+
import random
|
7 |
+
|
8 |
+
# Constants
|
9 |
+
SITES = ['Hyderabad', 'Kurnool', 'Bangalore', 'Warangal']
|
10 |
+
POLES_PER_SITE = 12
|
11 |
+
ALERT_THRESHOLD = 80 # Poles above this are red alert
|
12 |
+
|
13 |
+
# Generate dummy data
|
14 |
+
def generate_data():
|
15 |
+
data = []
|
16 |
+
for site in SITES:
|
17 |
+
for pole in range(1, POLES_PER_SITE + 1):
|
18 |
+
status = random.randint(0, 100)
|
19 |
+
data.append({'Site': site, 'Pole': f'P{pole}', 'Status': status})
|
20 |
+
return pd.DataFrame(data)
|
21 |
+
|
22 |
+
df = generate_data()
|
23 |
+
|
24 |
+
# Create heatmap figure
|
25 |
+
def create_heatmap(dataframe):
|
26 |
+
pivot_df = dataframe.pivot(index="Site", columns="Pole", values="Status")
|
27 |
+
fig = go.Figure(data=go.Heatmap(
|
28 |
+
z=pivot_df.values,
|
29 |
+
x=pivot_df.columns,
|
30 |
+
y=pivot_df.index,
|
31 |
+
colorscale="Viridis",
|
32 |
+
colorbar=dict(title="Status"),
|
33 |
+
zmin=0,
|
34 |
+
zmax=100
|
35 |
+
))
|
36 |
+
fig.update_layout(title="Pole Status Heatmap", height=500)
|
37 |
+
return fig
|
38 |
+
|
39 |
+
# Dash App
|
40 |
+
app = dash.Dash(__name__)
|
41 |
+
server = app.server # Needed for Hugging Face Spaces
|
42 |
+
|
43 |
+
# Blinking style (CSS)
|
44 |
+
blinking_style = {
|
45 |
+
"animation": "blinker 1s linear infinite",
|
46 |
+
"color": "red",
|
47 |
+
"fontWeight": "bold",
|
48 |
+
"fontSize": "20px",
|
49 |
+
"margin": "10px"
|
50 |
+
}
|
51 |
+
|
52 |
+
app.layout = html.Div([
|
53 |
+
html.H1("Pole Management Dashboard", style={'textAlign': 'center'}),
|
54 |
+
|
55 |
+
dcc.Graph(figure=create_heatmap(df)),
|
56 |
+
|
57 |
+
html.Div([
|
58 |
+
html.Div("🚨 Red Alert Poles:", style={"fontWeight": "bold", "marginTop": "20px"}),
|
59 |
+
html.Div([
|
60 |
+
html.Span(f"{row['Site']} - {row['Pole']}", style=blinking_style)
|
61 |
+
for _, row in df[df["Status"] > ALERT_THRESHOLD].iterrows()
|
62 |
+
])
|
63 |
+
], style={"textAlign": "center"}),
|
64 |
+
|
65 |
+
# Add CSS for blinking effect
|
66 |
+
html.Style("""
|
67 |
+
@keyframes blinker {
|
68 |
+
50% { opacity: 0; }
|
69 |
+
}
|
70 |
+
""")
|
71 |
+
])
|
72 |
+
|
73 |
+
if __name__ == "__main__":
|
74 |
+
app.run_server(debug=False, host="0.0.0.0", port=7860)
|