Sanjayraju30 commited on
Commit
8e7b080
·
verified ·
1 Parent(s): da4d0b5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +100 -0
app.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import dash
2
+ from dash import html, dcc
3
+ import pandas as pd
4
+ import plotly.graph_objects as go
5
+ import random
6
+
7
+ # Config
8
+ AREAS = ['Kurnool', 'Hyderabad', 'Ballari', 'Gadwal']
9
+ POLES_PER_AREA = 12
10
+ ALERT_LEVELS = ['Green', 'Yellow', 'Red']
11
+
12
+ def simulate_poles():
13
+ poles = []
14
+ for area in AREAS:
15
+ for i in range(1, POLES_PER_AREA + 1):
16
+ solar = round(random.uniform(3.0, 7.5), 2)
17
+ wind = round(random.uniform(0.5, 2.0), 2)
18
+ tilt = round(random.uniform(0, 10), 2)
19
+ vibration = round(random.uniform(0, 3), 2)
20
+ camera_status = random.choice(['Online', 'Offline'])
21
+ total_power = solar + wind
22
+ required_power = 6.5
23
+ alert = 'Green'
24
+ if total_power < 4 or tilt > 6 or vibration > 2.5:
25
+ alert = 'Yellow'
26
+ if total_power < 3 or tilt > 8 or vibration > 2.8:
27
+ alert = 'Red'
28
+ poles.append({
29
+ 'Area': area,
30
+ 'Pole': f'P{i}',
31
+ 'Solar (kWh)': solar,
32
+ 'Wind (kWh)': wind,
33
+ 'Power Total': total_power,
34
+ 'Tilt (°)': tilt,
35
+ 'Vibration (g)': vibration,
36
+ 'Camera': camera_status,
37
+ 'Alert': alert
38
+ })
39
+ return pd.DataFrame(poles)
40
+
41
+ df = simulate_poles()
42
+
43
+ # Convert alerts to numeric levels for color scale
44
+ alert_map = {'Green': 1, 'Yellow': 2, 'Red': 3}
45
+ df['AlertLevel'] = df['Alert'].map(alert_map)
46
+
47
+ def create_alert_heatmap(df):
48
+ pivot_df = df.pivot(index='Area', columns='Pole', values='AlertLevel')
49
+ color_scale = [
50
+ [0, "green"],
51
+ [0.5, "yellow"],
52
+ [1.0, "red"]
53
+ ]
54
+ fig = go.Figure(data=go.Heatmap(
55
+ z=pivot_df.values,
56
+ x=pivot_df.columns,
57
+ y=pivot_df.index,
58
+ colorscale=color_scale,
59
+ zmin=1,
60
+ zmax=3,
61
+ showscale=False,
62
+ hovertemplate="Pole: %{x}<br>Area: %{y}<br>Alert Level: %{z}<extra></extra>"
63
+ ))
64
+ fig.update_layout(title="Smart Pole Alert Heatmap", height=500)
65
+ return fig
66
+
67
+ app = dash.Dash(__name__)
68
+ server = app.server # Required for Hugging Face
69
+
70
+ app.layout = html.Div([
71
+ html.H1("Vedavathi Smart Pole Monitoring", style={"textAlign": "center"}),
72
+
73
+ dcc.Graph(figure=create_alert_heatmap(df)),
74
+
75
+ html.Div([
76
+ html.H3("🚨 Red Alert Poles", style={"color": "red", "textAlign": "center"}),
77
+ html.Div([
78
+ html.Span(f"{row['Area']} - {row['Pole']}", style={
79
+ "animation": "blinker 1s linear infinite",
80
+ "color": "red",
81
+ "fontWeight": "bold",
82
+ "fontSize": "18px",
83
+ "margin": "8px",
84
+ "display": "inline-block"
85
+ })
86
+ for _, row in df[df["Alert"] == "Red"].iterrows()
87
+ ], style={"textAlign": "center"})
88
+ ]),
89
+
90
+ dcc.Markdown('''
91
+ <style>
92
+ @keyframes blinker {
93
+ 50% { opacity: 0; }
94
+ }
95
+ </style>
96
+ ''', dangerously_allow_html=True)
97
+ ])
98
+
99
+ if __name__ == "__main__":
100
+ app.run_server(debug=False, host="0.0.0.0", port=7860)