Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,55 @@
|
|
1 |
-
import json
|
2 |
import streamlit as st
|
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
ax.
|
20 |
-
ax.set_xticks(
|
21 |
-
ax.set_yticks(
|
22 |
-
ax.grid(
|
23 |
-
|
24 |
-
#
|
25 |
-
for building in buildings:
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import json
|
3 |
import matplotlib.pyplot as plt
|
4 |
|
5 |
+
# Function to load and parse the JSON data
|
6 |
+
def load_data(filename):
|
7 |
+
with open(filename, 'r') as file:
|
8 |
+
data = json.load(file)
|
9 |
+
return data
|
10 |
+
|
11 |
+
# Function to draw the grid layout
|
12 |
+
def draw_grid(data):
|
13 |
+
# Create a figure and a grid of subplots
|
14 |
+
fig, ax = plt.subplots(figsize=(10, 10))
|
15 |
+
|
16 |
+
# Setting the grid size
|
17 |
+
nrows, ncols = data['size']['rows'], data['size']['columns']
|
18 |
+
ax.set_xlim(0, ncols)
|
19 |
+
ax.set_ylim(0, nrows)
|
20 |
+
ax.set_xticks(range(ncols+1))
|
21 |
+
ax.set_yticks(range(nrows+1))
|
22 |
+
ax.grid(True)
|
23 |
+
|
24 |
+
# Plotting each building
|
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 |
+
|
31 |
+
# Plotting the building on the grid
|
32 |
+
ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, fill=None, edgecolor='r', linewidth=2))
|
33 |
+
ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center')
|
34 |
+
|
35 |
+
# Setting labels and title
|
36 |
+
ax.set_xlabel('Columns')
|
37 |
+
ax.set_ylabel('Rows')
|
38 |
+
ax.set_title('Village Layout')
|
39 |
+
|
40 |
+
return fig
|
41 |
+
|
42 |
+
# Streamlit application starts here
|
43 |
+
def main():
|
44 |
+
st.title('Green Smart Village Layout')
|
45 |
+
|
46 |
+
# Load and display the data
|
47 |
+
data = load_data('grid.json') # Adjust this path if your grid.json is located elsewhere
|
48 |
+
st.json(data)
|
49 |
+
|
50 |
+
# Drawing and displaying the grid layout
|
51 |
+
fig = draw_grid(data)
|
52 |
+
st.pyplot(fig)
|
53 |
+
|
54 |
+
if __name__ == "__main__":
|
55 |
+
main()
|