Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,27 +2,10 @@ import streamlit as st
|
|
| 2 |
import json
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import time
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
st.set_page_config(layout="wide")
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
# HIN Number +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| 13 |
from SPARQLWrapper import SPARQLWrapper, JSON
|
| 14 |
from streamlit_agraph import agraph, TripleStore, Node, Edge, Config
|
| 15 |
-
import json
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
# Green Village ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
| 22 |
-
def load_data(filename):
|
| 23 |
-
with open(filename, 'r') as file:
|
| 24 |
-
data = json.load(file)
|
| 25 |
-
return data
|
| 26 |
|
| 27 |
# Color codes updated with hexadecimal values for compatibility
|
| 28 |
color_codes = {
|
|
@@ -49,35 +32,39 @@ color_codes = {
|
|
| 49 |
"outdoor_community_spaces": "#90EE90" # Light Green
|
| 50 |
}
|
| 51 |
|
| 52 |
-
# Function to
|
| 53 |
-
def
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
fig, ax = plt.subplots(figsize=(12, 12))
|
| 56 |
-
|
| 57 |
-
# Setting the grid size
|
| 58 |
nrows, ncols = data['size']['rows'], data['size']['columns']
|
| 59 |
ax.set_xlim(0, ncols)
|
| 60 |
ax.set_ylim(0, nrows)
|
| 61 |
ax.set_xticks(range(ncols+1))
|
| 62 |
ax.set_yticks(range(nrows+1))
|
| 63 |
ax.grid(True)
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
for building in data['buildings']:
|
| 67 |
-
# Extracting the building details
|
| 68 |
coords = building['coords']
|
| 69 |
b_type = building['type']
|
| 70 |
size = building['size']
|
| 71 |
-
color = color_codes.get(b_type, '#FFFFFF')
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=color, edgecolor=
|
| 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 |
-
|
| 78 |
-
for road in data.get('roads', []): # Check for roads in the data, default to empty list if not found
|
| 79 |
start, end = road['start'], road['end']
|
| 80 |
-
# Determine if the road is vertical or horizontal based on start and end coordinates
|
| 81 |
if start[0] == end[0]: # Vertical road
|
| 82 |
for y in range(min(start[1], end[1]), max(start[1], end[1]) + 1):
|
| 83 |
ax.add_patch(plt.Rectangle((start[0], nrows-y-1), 1, 1, color=road['color']))
|
|
@@ -85,76 +72,59 @@ def draw_grid(data):
|
|
| 85 |
for x in range(min(start[0], end[0]), max(start[0], end[0]) + 1):
|
| 86 |
ax.add_patch(plt.Rectangle((x, nrows-start[1]-1), 1, 1, color=road['color']))
|
| 87 |
|
| 88 |
-
|
| 89 |
-
# Reverse the y-axis numbers
|
| 90 |
-
# ax.invert_yaxis()
|
| 91 |
-
# Setting labels and title
|
| 92 |
ax.set_xlabel('Columns')
|
| 93 |
ax.set_ylabel('Rows')
|
| 94 |
ax.set_title('Village Layout with Color Coding')
|
| 95 |
-
|
| 96 |
return fig
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
# Streamlit application starts here
|
| 101 |
def main():
|
| 102 |
st.title('Green Smart Village Application')
|
| 103 |
-
|
| 104 |
-
# Creating three columns
|
| 105 |
col1, col2, col3 = st.columns(3)
|
| 106 |
-
|
| 107 |
with col1:
|
| 108 |
st.header("Today's Agenda")
|
| 109 |
-
# Example content for Today's Agenda
|
| 110 |
st.write("1. Morning Meeting\n2. Review Project Plans\n3. Lunch Break\n4. Site Visit\n5. Evening Wrap-up")
|
| 111 |
st.header("Agent Advisors")
|
| 112 |
-
st.write("Would you like to optimize your HIN number")
|
| 113 |
st.header("My Incentive")
|
| 114 |
st.write("Total incentive for HIN optimization")
|
| 115 |
-
|
| 116 |
with col2:
|
| 117 |
st.header("Green Smart Village Layout")
|
| 118 |
-
|
| 119 |
-
data = load_data('grid.json') # Ensure this path is correct
|
| 120 |
-
fig = draw_grid(data)
|
| 121 |
-
st.pyplot(fig)
|
| 122 |
-
|
| 123 |
-
# Interactivity: Selecting a building to display sensor data
|
| 124 |
building_options = [f"{bld['type']} at ({bld['coords'][0]}, {bld['coords'][1]})" for bld in data['buildings']]
|
| 125 |
selected_building = st.selectbox("Select a building to view sensors:", options=building_options)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
selected_index = building_options.index(selected_building)
|
| 127 |
sensors = data['buildings'][selected_index]['sensors']
|
| 128 |
st.write(f"Sensors in selected building: {', '.join(sensors)}")
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
with col3:
|
| 133 |
st.header("Check Your HIN Number")
|
| 134 |
-
config = Config(height=400, width=400, nodeHighlightBehavior=True, highlightColor="#F7A7A6", directed=True,
|
| 135 |
-
collapsible=True)
|
| 136 |
|
| 137 |
-
#based on Insurance Fraud
|
| 138 |
with open("data/fraud.json", encoding="utf8") as f:
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
|
| 153 |
hin_number = st.text_input("Enter your HIN number:")
|
| 154 |
if hin_number:
|
| 155 |
-
st.write("HIN number details...")
|
| 156 |
-
|
| 157 |
-
|
| 158 |
|
| 159 |
if __name__ == "__main__":
|
| 160 |
-
main()
|
|
|
|
| 2 |
import json
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
from SPARQLWrapper import SPARQLWrapper, JSON
|
| 6 |
from streamlit_agraph import agraph, TripleStore, Node, Edge, Config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
st.set_page_config(layout="wide")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Color codes updated with hexadecimal values for compatibility
|
| 11 |
color_codes = {
|
|
|
|
| 32 |
"outdoor_community_spaces": "#90EE90" # Light Green
|
| 33 |
}
|
| 34 |
|
| 35 |
+
# Function to load and parse the JSON data
|
| 36 |
+
def load_data(filename):
|
| 37 |
+
with open(filename, 'r') as file:
|
| 38 |
+
data = json.load(file)
|
| 39 |
+
return data
|
| 40 |
+
|
| 41 |
+
# Function to draw the grid layout with color coding and to highlight a selected building
|
| 42 |
+
def draw_grid(data, highlight=None):
|
| 43 |
fig, ax = plt.subplots(figsize=(12, 12))
|
|
|
|
|
|
|
| 44 |
nrows, ncols = data['size']['rows'], data['size']['columns']
|
| 45 |
ax.set_xlim(0, ncols)
|
| 46 |
ax.set_ylim(0, nrows)
|
| 47 |
ax.set_xticks(range(ncols+1))
|
| 48 |
ax.set_yticks(range(nrows+1))
|
| 49 |
ax.grid(True)
|
| 50 |
+
|
| 51 |
+
highlight_coords = None
|
| 52 |
+
if highlight is not None:
|
| 53 |
+
highlight_type, highlight_coords_str = highlight.split(' at ')
|
| 54 |
+
highlight_coords = tuple(map(int, highlight_coords_str.strip('()').split(',')))
|
| 55 |
+
|
| 56 |
for building in data['buildings']:
|
|
|
|
| 57 |
coords = building['coords']
|
| 58 |
b_type = building['type']
|
| 59 |
size = building['size']
|
| 60 |
+
color = color_codes.get(b_type, '#FFFFFF')
|
| 61 |
+
edgecolor = 'red' if coords == highlight_coords else 'black'
|
| 62 |
+
linewidth = 2 if coords == highlight_coords else 1
|
| 63 |
+
ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=color, edgecolor=edgecolor, linewidth=linewidth))
|
| 64 |
ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center', fontsize=8, color='black')
|
| 65 |
|
| 66 |
+
for road in data.get('roads', []):
|
|
|
|
| 67 |
start, end = road['start'], road['end']
|
|
|
|
| 68 |
if start[0] == end[0]: # Vertical road
|
| 69 |
for y in range(min(start[1], end[1]), max(start[1], end[1]) + 1):
|
| 70 |
ax.add_patch(plt.Rectangle((start[0], nrows-y-1), 1, 1, color=road['color']))
|
|
|
|
| 72 |
for x in range(min(start[0], end[0]), max(start[0], end[0]) + 1):
|
| 73 |
ax.add_patch(plt.Rectangle((x, nrows-start[1]-1), 1, 1, color=road['color']))
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
ax.set_xlabel('Columns')
|
| 76 |
ax.set_ylabel('Rows')
|
| 77 |
ax.set_title('Village Layout with Color Coding')
|
|
|
|
| 78 |
return fig
|
| 79 |
|
|
|
|
|
|
|
| 80 |
# Streamlit application starts here
|
| 81 |
def main():
|
| 82 |
st.title('Green Smart Village Application')
|
| 83 |
+
|
|
|
|
| 84 |
col1, col2, col3 = st.columns(3)
|
| 85 |
+
|
| 86 |
with col1:
|
| 87 |
st.header("Today's Agenda")
|
|
|
|
| 88 |
st.write("1. Morning Meeting\n2. Review Project Plans\n3. Lunch Break\n4. Site Visit\n5. Evening Wrap-up")
|
| 89 |
st.header("Agent Advisors")
|
| 90 |
+
st.write("Would you like to optimize your HIN number?")
|
| 91 |
st.header("My Incentive")
|
| 92 |
st.write("Total incentive for HIN optimization")
|
| 93 |
+
|
| 94 |
with col2:
|
| 95 |
st.header("Green Smart Village Layout")
|
| 96 |
+
data = load_data('grid.json')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
building_options = [f"{bld['type']} at ({bld['coords'][0]}, {bld['coords'][1]})" for bld in data['buildings']]
|
| 98 |
selected_building = st.selectbox("Select a building to view sensors:", options=building_options)
|
| 99 |
+
|
| 100 |
+
fig = draw_grid(data, highlight=selected_building)
|
| 101 |
+
st.pyplot(fig)
|
| 102 |
+
|
| 103 |
selected_index = building_options.index(selected_building)
|
| 104 |
sensors = data['buildings'][selected_index]['sensors']
|
| 105 |
st.write(f"Sensors in selected building: {', '.join(sensors)}")
|
| 106 |
|
|
|
|
|
|
|
| 107 |
with col3:
|
| 108 |
st.header("Check Your HIN Number")
|
| 109 |
+
config = Config(height=400, width=400, nodeHighlightBehavior=True, highlightColor="#F7A7A6", directed=True, collapsible=True)
|
|
|
|
| 110 |
|
|
|
|
| 111 |
with open("data/fraud.json", encoding="utf8") as f:
|
| 112 |
+
fraud_file = json.loads(f.read())
|
| 113 |
+
st.session_state['fraud_topic'] = fraud_file
|
| 114 |
+
fraud_store = TripleStore()
|
| 115 |
+
for sub_graph in fraud_file["children"]:
|
| 116 |
+
fraud_store.add_triple(fraud_file["name"], "has_subgroup", sub_graph["name"], picture=fraud_file["img"])
|
| 117 |
+
for node in sub_graph["children"]:
|
| 118 |
+
node1 = node["role"]
|
| 119 |
+
link = "belongs_to"
|
| 120 |
+
node2 = sub_graph["name"]
|
| 121 |
+
pic = node["img"]
|
| 122 |
+
fraud_store.add_triple(node1, link, node2, picture=pic)
|
| 123 |
+
agraph(list(fraud_store.getNodes()), list(fraud_store.getEdges()), config)
|
|
|
|
| 124 |
|
| 125 |
hin_number = st.text_input("Enter your HIN number:")
|
| 126 |
if hin_number:
|
| 127 |
+
st.write("HIN number details...")
|
|
|
|
|
|
|
| 128 |
|
| 129 |
if __name__ == "__main__":
|
| 130 |
+
main()
|