Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,31 @@ def load_data(filename):
|
|
8 |
data = json.load(file)
|
9 |
return data
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
# Function to draw the grid layout with color coding
|
12 |
def draw_grid(data):
|
13 |
# Create a figure and a grid of subplots
|
@@ -21,17 +46,17 @@ def draw_grid(data):
|
|
21 |
ax.set_yticks(range(nrows+1))
|
22 |
ax.grid(True)
|
23 |
|
24 |
-
# Plotting each building with its assigned color
|
25 |
for building in data['buildings']:
|
26 |
# Extracting the building details
|
27 |
coords = building['coords']
|
28 |
b_type = building['type']
|
29 |
size = building['size']
|
30 |
-
color =
|
31 |
|
32 |
-
# Plotting the building on the grid
|
33 |
ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=color, edgecolor='black', linewidth=1))
|
34 |
-
ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center', fontsize=8)
|
35 |
|
36 |
# Setting labels and title
|
37 |
ax.set_xlabel('Columns')
|
@@ -45,7 +70,7 @@ def main():
|
|
45 |
st.title('Green Smart Village Layout with Color Coding')
|
46 |
|
47 |
# Load and display the data with color coding
|
48 |
-
data = load_data('
|
49 |
# st.json(data)
|
50 |
|
51 |
# Drawing and displaying the grid layout with color coding
|
|
|
8 |
data = json.load(file)
|
9 |
return data
|
10 |
|
11 |
+
# Color codes updated with hexadecimal values for compatibility
|
12 |
+
color_codes = {
|
13 |
+
"residential": "#ADD8E6", # Light Blue
|
14 |
+
"commercial": "#008000", # Green
|
15 |
+
"community_facilities": "#FFFF00", # Yellow
|
16 |
+
"school": "#FFFF00", # Yellow
|
17 |
+
"healthcare_facility": "#FFFF00", # Yellow
|
18 |
+
"green_space": "#006400", # Dark Green
|
19 |
+
"utility_infrastructure": "#006400", # Dark Green
|
20 |
+
"emergency_services": "#FF0000", # Red
|
21 |
+
"cultural_facilities": "#800080", # Purple
|
22 |
+
"recreational_facilities": "#800080", # Purple
|
23 |
+
"innovation_center": "#008000", # Green
|
24 |
+
"elderly_care_home": "#FFFF00", # Yellow
|
25 |
+
"childcare_centers": "#FFFF00", # Yellow
|
26 |
+
"places_of_worship": "#800080", # Purple
|
27 |
+
"event_spaces": "#800080", # Purple
|
28 |
+
"guest_housing": "#FFA500", # Orange
|
29 |
+
"pet_care_facilities": "#FFA500", # Orange
|
30 |
+
"public_sanitation_facilities": "#808080", # Grey
|
31 |
+
"environmental_monitoring_stations": "#006400", # Dark Green
|
32 |
+
"disaster_preparedness_center": "#808080", # Grey
|
33 |
+
"outdoor_community_spaces": "#006400" # Dark Green
|
34 |
+
}
|
35 |
+
|
36 |
# Function to draw the grid layout with color coding
|
37 |
def draw_grid(data):
|
38 |
# Create a figure and a grid of subplots
|
|
|
46 |
ax.set_yticks(range(nrows+1))
|
47 |
ax.grid(True)
|
48 |
|
49 |
+
# Plotting each building with its assigned color from the color_codes dictionary
|
50 |
for building in data['buildings']:
|
51 |
# Extracting the building details
|
52 |
coords = building['coords']
|
53 |
b_type = building['type']
|
54 |
size = building['size']
|
55 |
+
color = color_codes.get(b_type, '#FFFFFF') # Default color is white if not specified
|
56 |
|
57 |
+
# Plotting the building on the grid with color
|
58 |
ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=color, edgecolor='black', linewidth=1))
|
59 |
+
ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center', fontsize=8, color='black')
|
60 |
|
61 |
# Setting labels and title
|
62 |
ax.set_xlabel('Columns')
|
|
|
70 |
st.title('Green Smart Village Layout with Color Coding')
|
71 |
|
72 |
# Load and display the data with color coding
|
73 |
+
data = load_data('formatted_grid_20x20_colored.json') # Make sure this path is correct
|
74 |
# st.json(data)
|
75 |
|
76 |
# Drawing and displaying the grid layout with color coding
|