Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -37,7 +37,7 @@ color_codes = {
|
|
37 |
}
|
38 |
|
39 |
# Function to draw the grid with optional highlighting and roads
|
40 |
-
def draw_grid(data,
|
41 |
fig, ax = plt.subplots(figsize=(12, 12))
|
42 |
nrows, ncols = data['size']['rows'], data['size']['columns']
|
43 |
ax.set_xlim(0, ncols)
|
@@ -92,30 +92,18 @@ def main():
|
|
92 |
st.header("My Incentive")
|
93 |
st.write("Total incentive for HIN optimization")
|
94 |
|
95 |
-
|
96 |
with col2:
|
97 |
st.header("Green Smart Village Layout")
|
98 |
-
data = load_data('grid.json')
|
99 |
-
|
100 |
-
# Create a combined list of buildings and roads for the dropdown
|
101 |
-
building_options = [f"Building: {bld['type']} at ({bld['coords'][0]}, {bld['coords'][1]})" for bld in data['buildings']]
|
102 |
-
road_options = [f"Road: {road['id']}" for road in data['roads']]
|
103 |
-
all_options = building_options + road_options
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
selected_building_coords = data['buildings'][selected_index]['coords']
|
111 |
-
highlight_element = {'type': 'building', 'coords': selected_building_coords}
|
112 |
-
else:
|
113 |
-
selected_index = road_options.index(selected_option)
|
114 |
-
selected_road_coords = data['roads'][selected_index]['start'], data['roads'][selected_index]['end']
|
115 |
-
highlight_element = {'type': 'road', 'coords': selected_road_coords}
|
116 |
|
117 |
-
# Draw the grid with the selected
|
118 |
-
fig = draw_grid(data,
|
119 |
st.pyplot(fig)
|
120 |
|
121 |
with col3:
|
|
|
37 |
}
|
38 |
|
39 |
# Function to draw the grid with optional highlighting and roads
|
40 |
+
def draw_grid(data, highlight_coords=None):
|
41 |
fig, ax = plt.subplots(figsize=(12, 12))
|
42 |
nrows, ncols = data['size']['rows'], data['size']['columns']
|
43 |
ax.set_xlim(0, ncols)
|
|
|
92 |
st.header("My Incentive")
|
93 |
st.write("Total incentive for HIN optimization")
|
94 |
|
|
|
95 |
with col2:
|
96 |
st.header("Green Smart Village Layout")
|
97 |
+
data = load_data('grid.json') # Ensure this path is correct
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
+
# Dropdown for selecting a building
|
100 |
+
building_options = [f"{bld['type']} at ({bld['coords'][0]}, {bld['coords'][1]})" for bld in data['buildings']]
|
101 |
+
selected_building = st.selectbox("Select a building to highlight:", options=building_options)
|
102 |
+
selected_index = building_options.index(selected_building)
|
103 |
+
selected_building_coords = data['buildings'][selected_index]['coords']
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
+
# Draw the grid with the selected building highlighted and roads
|
106 |
+
fig = draw_grid(data, highlight_coords=selected_building_coords)
|
107 |
st.pyplot(fig)
|
108 |
|
109 |
with col3:
|