import streamlit as st import json import pandas as pd 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 # Function to draw the grid layout def draw_grid(data): # Create a figure and a grid of subplots fig, ax = plt.subplots(figsize=(10, 10)) # 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 for building in data['buildings']: # Extracting the building details coords = building['coords'] b_type = building['type'] size = building['size'] # Plotting the building on the grid ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, fill=None, edgecolor='r', linewidth=2)) ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center') # Setting labels and title ax.set_xlabel('Columns') ax.set_ylabel('Rows') ax.set_title('Village Layout') return fig # Streamlit application starts here def main(): st.title('Green Smart Village Layout') # Load and display the data data = load_data('grid.json') # Make sure to adjust the path if necessary # st.json(data) # Drawing and displaying the grid layout fig = draw_grid(data) st.pyplot(fig) if __name__ == "__main__": main()