Sanjayraju30 commited on
Commit
8514584
·
verified ·
1 Parent(s): ecb7119

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -25
app.py CHANGED
@@ -5,24 +5,25 @@ import numpy as np
5
  import plotly.graph_objects as go
6
  import random
7
 
 
8
  SITES = ['Hyderabad', 'Kurnool', 'Bangalore', 'Warangal']
9
  POLES_PER_SITE = 12
10
  ALERT_THRESHOLD = 80
11
 
 
12
  def generate_data():
13
- return pd.DataFrame([
14
- {
15
- 'Site': site,
16
- 'Pole': f'P{pole}',
17
- 'Status': random.randint(0, 100)
18
- }
19
- for site in SITES
20
- for pole in range(1, POLES_PER_SITE + 1)
21
- ])
22
  df = generate_data()
23
 
24
- def create_heatmap(df):
25
- pivot_df = df.pivot(index="Site", columns="Pole", values="Status")
 
26
  fig = go.Figure(data=go.Heatmap(
27
  z=pivot_df.values,
28
  x=pivot_df.columns,
@@ -35,36 +36,39 @@ def create_heatmap(df):
35
  fig.update_layout(title="Pole Status Heatmap", height=500)
36
  return fig
37
 
 
38
  app = dash.Dash(__name__)
39
- server = app.server
40
 
 
41
  app.layout = html.Div([
42
  html.H1("Pole Management Dashboard", style={'textAlign': 'center'}),
43
  dcc.Graph(figure=create_heatmap(df)),
44
-
45
  html.Div([
46
- html.Div("🚨 Red Alert Poles:", style={"fontWeight": "bold", "marginTop": "20px"}),
47
  html.Div([
48
  html.Span(f"{row['Site']} - {row['Pole']}", style={
49
  "animation": "blinker 1s linear infinite",
50
  "color": "red",
51
  "fontWeight": "bold",
52
  "fontSize": "20px",
53
- "margin": "10px"
 
54
  })
55
  for _, row in df[df["Status"] > ALERT_THRESHOLD].iterrows()
56
- ])
57
- ], style={"textAlign": "center"}),
58
 
59
  dcc.Markdown('''
60
- <style>
61
- @keyframes blinker {
62
- 50% { opacity: 0; }
63
- }
64
- </style>
65
  ''', dangerously_allow_html=True)
66
  ])
67
 
68
- if __name__ == "__main__":
69
- app.run_server(debug=False, host="0.0.0.0", port=7860)
70
-
 
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
12
 
13
+ # Generate sample pole 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,
 
36
  fig.update_layout(title="Pole Status Heatmap", height=500)
37
  return fig
38
 
39
+ # Dash app setup
40
  app = dash.Dash(__name__)
41
+ server = app.server # for Hugging Face Spaces
42
 
43
+ # App layout
44
  app.layout = html.Div([
45
  html.H1("Pole Management Dashboard", style={'textAlign': 'center'}),
46
  dcc.Graph(figure=create_heatmap(df)),
47
+
48
  html.Div([
49
+ html.H3("🚨 Red Alert Poles:", style={"textAlign": "center", "color": "red"}),
50
  html.Div([
51
  html.Span(f"{row['Site']} - {row['Pole']}", style={
52
  "animation": "blinker 1s linear infinite",
53
  "color": "red",
54
  "fontWeight": "bold",
55
  "fontSize": "20px",
56
+ "margin": "10px",
57
+ "display": "inline-block"
58
  })
59
  for _, row in df[df["Status"] > ALERT_THRESHOLD].iterrows()
60
+ ], style={"textAlign": "center"})
61
+ ]),
62
 
63
  dcc.Markdown('''
64
+ <style>
65
+ @keyframes blinker {
66
+ 50% { opacity: 0; }
67
+ }
68
+ </style>
69
  ''', dangerously_allow_html=True)
70
  ])
71
 
72
+ # Run server
73
+ if __name__ == '__main__':
74
+ app.run_server(debug=False, host='0.0.0.0', port=7860)