Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,11 +4,11 @@ import pandas as pd
|
|
4 |
import plotly.graph_objects as go
|
5 |
import random
|
6 |
|
7 |
-
#
|
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:
|
@@ -19,18 +19,21 @@ def simulate_poles():
|
|
19 |
vibration = round(random.uniform(0, 3), 2)
|
20 |
camera_status = random.choice(['Online', 'Offline'])
|
21 |
total_power = solar + wind
|
22 |
-
|
23 |
-
alert
|
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
|
34 |
'Tilt (°)': tilt,
|
35 |
'Vibration (g)': vibration,
|
36 |
'Camera': camera_status,
|
@@ -38,12 +41,12 @@ def simulate_poles():
|
|
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 = [
|
@@ -64,8 +67,9 @@ def create_alert_heatmap(df):
|
|
64 |
fig.update_layout(title="Smart Pole Alert Heatmap", height=500)
|
65 |
return fig
|
66 |
|
|
|
67 |
app = dash.Dash(__name__)
|
68 |
-
server = app.server #
|
69 |
|
70 |
app.layout = html.Div([
|
71 |
html.H1("Vedavathi Smart Pole Monitoring", style={"textAlign": "center"}),
|
@@ -87,21 +91,14 @@ app.layout = html.Div([
|
|
87 |
], style={"textAlign": "center"})
|
88 |
]),
|
89 |
|
90 |
-
|
91 |
-
<style>
|
92 |
@keyframes blinker {
|
93 |
50% { opacity: 0; }
|
94 |
}
|
95 |
-
|
96 |
-
''', dangerously_allow_html=True)
|
97 |
])
|
98 |
|
99 |
if __name__ == "__main__":
|
100 |
-
app.run(
|
101 |
-
debug=False,
|
102 |
-
host="0.0.0.0",
|
103 |
-
port=7860
|
104 |
-
)
|
105 |
-
|
106 |
|
107 |
|
|
|
4 |
import plotly.graph_objects as go
|
5 |
import random
|
6 |
|
7 |
+
# Configuration
|
8 |
AREAS = ['Kurnool', 'Hyderabad', 'Ballari', 'Gadwal']
|
9 |
POLES_PER_AREA = 12
|
|
|
10 |
|
11 |
+
# Simulate poles
|
12 |
def simulate_poles():
|
13 |
poles = []
|
14 |
for area in AREAS:
|
|
|
19 |
vibration = round(random.uniform(0, 3), 2)
|
20 |
camera_status = random.choice(['Online', 'Offline'])
|
21 |
total_power = solar + wind
|
22 |
+
|
23 |
+
# Determine alert level
|
|
|
|
|
24 |
if total_power < 3 or tilt > 8 or vibration > 2.8:
|
25 |
alert = 'Red'
|
26 |
+
elif total_power < 4 or tilt > 6 or vibration > 2.5:
|
27 |
+
alert = 'Yellow'
|
28 |
+
else:
|
29 |
+
alert = 'Green'
|
30 |
+
|
31 |
poles.append({
|
32 |
'Area': area,
|
33 |
'Pole': f'P{i}',
|
34 |
'Solar (kWh)': solar,
|
35 |
'Wind (kWh)': wind,
|
36 |
+
'Total Power': total_power,
|
37 |
'Tilt (°)': tilt,
|
38 |
'Vibration (g)': vibration,
|
39 |
'Camera': camera_status,
|
|
|
41 |
})
|
42 |
return pd.DataFrame(poles)
|
43 |
|
44 |
+
# Create data
|
45 |
df = simulate_poles()
|
|
|
|
|
46 |
alert_map = {'Green': 1, 'Yellow': 2, 'Red': 3}
|
47 |
df['AlertLevel'] = df['Alert'].map(alert_map)
|
48 |
|
49 |
+
# Create heatmap
|
50 |
def create_alert_heatmap(df):
|
51 |
pivot_df = df.pivot(index='Area', columns='Pole', values='AlertLevel')
|
52 |
color_scale = [
|
|
|
67 |
fig.update_layout(title="Smart Pole Alert Heatmap", height=500)
|
68 |
return fig
|
69 |
|
70 |
+
# App
|
71 |
app = dash.Dash(__name__)
|
72 |
+
server = app.server # for Hugging Face
|
73 |
|
74 |
app.layout = html.Div([
|
75 |
html.H1("Vedavathi Smart Pole Monitoring", style={"textAlign": "center"}),
|
|
|
91 |
], style={"textAlign": "center"})
|
92 |
]),
|
93 |
|
94 |
+
html.Style("""
|
|
|
95 |
@keyframes blinker {
|
96 |
50% { opacity: 0; }
|
97 |
}
|
98 |
+
""")
|
|
|
99 |
])
|
100 |
|
101 |
if __name__ == "__main__":
|
102 |
+
app.run(debug=False, host="0.0.0.0", port=7860)
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
|