Spaces:
Runtime error
Runtime error
File size: 3,675 Bytes
21e744a 42adde1 6f59340 21e744a 42adde1 252ec67 d1cd9a8 252ec67 ce3a46b 252ec67 ce3a46b d1cd9a8 252ec67 ce3a46b 252ec67 d797973 ce3a46b 26989f6 ce3a46b 252ec67 baa38fa 42adde1 baa38fa 42adde1 252ec67 42adde1 252ec67 42adde1 252ec67 baa38fa 252ec67 a6436b7 42adde1 baa38fa 42adde1 d797973 42adde1 baa38fa ca5d95d e6ee53b 42adde1 baa38fa 42adde1 46266bd 42adde1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
import streamlit as st
import json
import matplotlib.pyplot as plt
# Function to load and parse the JSON data
def load_data(filename):
with open(filename, 'r') as file:
data = json.load(file)
return data
# Color codes updated with hexadecimal values for compatibility
color_codes = {
"residential": "#ADD8E6", # Light Blue
"commercial": "#90EE90", # Light Green
"community_facilities": "#FFFF00", # Yellow
"school": "#FFFF00", # Yellow
"healthcare_facility": "#FFFF00", # Yellow
"green_space": "#90EE90", # Light Green
"utility_infrastructure": "#90EE90", # Light Green
"emergency_services": "#FF0000", # Red
"cultural_facilities": "#D8BFD8", # Light Purple
"recreational_facilities": "#D8BFD8", # Light Purple
"innovation_center": "#90EE90", # Light Green
"elderly_care_home": "#FFFF00", # Yellow
"childcare_centers": "#FFFF00", # Yellow
"places_of_worship": "#D8BFD8", # Light Purple
"event_spaces": "#D8BFD8", # Light Purple
"guest_housing": "#FFA500", # Orange
"pet_care_facilities": "#FFA500", # Orange
"public_sanitation_facilities": "#A0A0A0", # Grey
"environmental_monitoring_stations": "#90EE90", # Light Green
"disaster_preparedness_center": "#A0A0A0", # Grey
"outdoor_community_spaces": "#90EE90" # Light Green
}
# Function to draw the grid layout with color coding
def draw_grid(data):
# Create a figure and a grid of subplots
fig, ax = plt.subplots(figsize=(12, 12))
# Setting the grid size
nrows, ncols = data['size']['rows'], data['size']['columns']
ax.set_xlim(0, ncols)
ax.set_ylim(0, nrows)
ax.set_xticks(range(ncols+1))
ax.set_yticks(range(nrows+1))
ax.grid(True)
# Plotting each building with its assigned color from the color_codes dictionary
for building in data['buildings']:
# Extracting the building details
coords = building['coords']
b_type = building['type']
size = building['size']
color = color_codes.get(b_type, '#FFFFFF') # Default color is white if not specified
# Plotting the building on the grid with color
ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=color, edgecolor='black', linewidth=1))
ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center', fontsize=8, color='black')
# Draw roads
for road in data.get('roads', []): # Check for roads in the data, default to empty list if not found
start, end = road['start'], road['end']
# Determine if the road is vertical or horizontal based on start and end coordinates
if start[0] == end[0]: # Vertical road
for y in range(min(start[1], end[1]), max(start[1], end[1]) + 1):
ax.add_patch(plt.Rectangle((start[0], nrows-y-1), 1, 1, color=road['color']))
else: # Horizontal road
for x in range(min(start[0], end[0]), max(start[0], end[0]) + 1):
ax.add_patch(plt.Rectangle((x, nrows-start[1]-1), 1, 1, color=road['color']))
# Setting labels and title
ax.set_xlabel('Columns')
ax.set_ylabel('Rows')
ax.set_title('Village Layout with Color Coding')
return fig
# Streamlit application starts here
def main():
st.title('Green Smart Village Layout')
# Load and display the data with color coding
data = load_data('grid.json') # Make sure this path is correct
# st.json(data)
# Drawing and displaying the grid layout with color coding
fig = draw_grid(data)
st.pyplot(fig)
if __name__ == "__main__":
main()
|