Spaces:
Runtime error
Runtime error
eaglelandsonce
commited on
Commit
•
8bb3175
1
Parent(s):
a09b6d4
Update app.py
Browse files
app.py
CHANGED
@@ -43,6 +43,44 @@ color_codes = {
|
|
43 |
}
|
44 |
|
45 |
# Function to draw the grid with optional highlighting
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
def draw_grid(data, highlight_coords=None):
|
47 |
fig, ax = plt.subplots(figsize=(12, 12))
|
48 |
nrows, ncols = data['size']['rows'], data['size']['columns']
|
@@ -70,6 +108,8 @@ def draw_grid(data, highlight_coords=None):
|
|
70 |
ax.set_title('Village Layout with Color Coding')
|
71 |
return fig
|
72 |
|
|
|
|
|
73 |
# Main Streamlit app function
|
74 |
def main():
|
75 |
st.title('Green Smart Village Application')
|
|
|
43 |
}
|
44 |
|
45 |
# Function to draw the grid with optional highlighting
|
46 |
+
|
47 |
+
def draw_grid(data, highlight_coords=None):
|
48 |
+
fig, ax = plt.subplots(figsize=(12, 12))
|
49 |
+
nrows, ncols = data['size']['rows'], data['size']['columns']
|
50 |
+
ax.set_xlim(0, ncols)
|
51 |
+
ax.set_ylim(0, nrows)
|
52 |
+
ax.set_xticks(range(ncols+1))
|
53 |
+
ax.set_yticks(range(nrows+1))
|
54 |
+
ax.grid(True)
|
55 |
+
|
56 |
+
# Draw roads
|
57 |
+
for road in data.get('roads', []): # Default to empty list if no roads key
|
58 |
+
start = road['start']
|
59 |
+
end = road['end']
|
60 |
+
color = color_codes.get("road", '#898989') # Default color is gray for roads
|
61 |
+
ax.plot([start[1], end[1]], [nrows-start[0], nrows-end[0]], color=color, linewidth=2) # Adjust coordinates for matplotlib
|
62 |
+
|
63 |
+
# Draw buildings
|
64 |
+
for building in data['buildings']:
|
65 |
+
coords = building['coords']
|
66 |
+
b_type = building['type']
|
67 |
+
size = building['size']
|
68 |
+
color = color_codes.get(b_type, '#FFFFFF') # Default color is white if not specified
|
69 |
+
|
70 |
+
if highlight_coords and (coords[0], coords[1]) == tuple(highlight_coords):
|
71 |
+
highlighted_color = "#FFD700" # Gold for highlighting
|
72 |
+
ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=highlighted_color, edgecolor='black', linewidth=2))
|
73 |
+
else:
|
74 |
+
ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=color, edgecolor='black', linewidth=1))
|
75 |
+
ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center', fontsize=8, color='black')
|
76 |
+
|
77 |
+
ax.set_xlabel('Columns')
|
78 |
+
ax.set_ylabel('Rows')
|
79 |
+
ax.set_title('Village Layout with Color Coding')
|
80 |
+
return fig
|
81 |
+
|
82 |
+
|
83 |
+
"""
|
84 |
def draw_grid(data, highlight_coords=None):
|
85 |
fig, ax = plt.subplots(figsize=(12, 12))
|
86 |
nrows, ncols = data['size']['rows'], data['size']['columns']
|
|
|
108 |
ax.set_title('Village Layout with Color Coding')
|
109 |
return fig
|
110 |
|
111 |
+
"""
|
112 |
+
|
113 |
# Main Streamlit app function
|
114 |
def main():
|
115 |
st.title('Green Smart Village Application')
|