Spaces:
Runtime error
Runtime error
import streamlit as st | |
import json | |
import matplotlib.pyplot as plt | |
import time | |
from PIL import Image | |
from streamlit_image_comparison import image_comparison | |
st.set_page_config(layout="wide") | |
# HIN Number +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
from SPARQLWrapper import SPARQLWrapper, JSON | |
from streamlit_agraph import agraph, TripleStore, Node, Edge, Config | |
import json | |
# Function to load JSON data | |
def load_data(filename): | |
with open(filename, 'r') as file: | |
data = json.load(file) | |
return data | |
# Dictionary for color codes | |
color_codes = { | |
"residential": "#ADD8E6", | |
"commercial": "#90EE90", | |
"community_facilities": "#FFFF00", | |
"school": "#FFFF00", | |
"healthcare_facility": "#FFFF00", | |
"green_space": "#90EE90", | |
"utility_infrastructure": "#90EE90", | |
"emergency_services": "#FF0000", | |
"cultural_facilities": "#D8BFD8", | |
"recreational_facilities": "#D8BFD8", | |
"innovation_center": "#90EE90", | |
"elderly_care_home": "#FFFF00", | |
"childcare_centers": "#FFFF00", | |
"places_of_worship": "#D8BFD8", | |
"event_spaces": "#D8BFD8", | |
"guest_housing": "#FFA500", | |
"pet_care_facilities": "#FFA500", | |
"public_sanitation_facilities": "#A0A0A0", | |
"environmental_monitoring_stations": "#90EE90", | |
"disaster_preparedness_center": "#A0A0A0", | |
"outdoor_community_spaces": "#90EE90", | |
# Add other types with their corresponding colors | |
} | |
# Function to draw the grid with optional highlighting | |
def draw_grid(data, highlight_coords=None): | |
fig, ax = plt.subplots(figsize=(12, 12)) | |
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) | |
# Draw roads with a specified grey color | |
road_color = "#606060" # Light grey; change to "#505050" for dark grey | |
for road in data.get('roads', []): # Check for roads in the data | |
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'])) | |
# Draw buildings | |
for building in data['buildings']: | |
coords = building['coords'] | |
b_type = building['type'] | |
size = building['size'] | |
color = color_codes.get(b_type, '#FFFFFF') # Default color is white if not specified | |
if highlight_coords and (coords[0], coords[1]) == tuple(highlight_coords): | |
highlighted_color = "#FFD700" # Gold for highlighting | |
ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=highlighted_color, edgecolor='black', linewidth=2)) | |
else: | |
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') | |
ax.set_xlabel('Columns') | |
ax.set_ylabel('Rows') | |
ax.set_title('Village Layout with Color Coding') | |
return fig | |
# Tabs +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
# Create the main app with three tabs | |
tab1, tab2, tab3 = st.tabs(["Interpretive Number","Green Village", "Control Room"]) | |
with tab1: | |
st.header("Engineering Tools") | |
# Divide the page into three columns | |
col1, col2 = st.columns(2) | |
with col1: | |
st.header("Human Interpretive Number (HIN)") | |
st.write("") | |
"How do LLMs interpret us and over “a period” of time what is the result of our interaction with them?" | |
st.write("") | |
image_comparison( | |
img1="./data/robot.jpg", | |
img2="./data/life.jpg", | |
label1="What the LMM Sees (Simulated Life)", | |
label2="What we See (Real Life)", | |
) | |
with col2: | |
st.header("Custom GPT Engineering Tools") | |
with tab2: | |
st.header("Green Smart Village Application") | |
# Divide the page into three columns | |
col1, col2, col3 = st.columns(3) | |
with col1: | |
st.header("Today's Agenda") | |
st.write("1. Morning Meeting\n2. Review Project Plans\n3. Lunch Break\n4. Site Visit\n5. Evening Wrap-up") | |
st.header("Agent Advisors") | |
st.write("Would you like to optimize your HIN number?") | |
st.header("My Incentive") | |
st.write("Total incentive for HIN optimization") | |
with col2: | |
st.header("Green Smart Village Layout") | |
data = load_data('grid.json') # Ensure this path is correct | |
# Dropdown for selecting a building | |
building_options = [f"{bld['type']} at ({bld['coords'][0]}, {bld['coords'][1]})" for bld in data['buildings']] | |
selected_building = st.selectbox("Select a building to highlight:", options=building_options) | |
selected_index = building_options.index(selected_building) | |
selected_building_coords = data['buildings'][selected_index]['coords'] | |
# Draw the grid with the selected building highlighted | |
fig = draw_grid(data, highlight_coords=selected_building_coords) | |
st.pyplot(fig) | |
# Assuming sensors are defined in your data, display them | |
sensors = data['buildings'][selected_index].get('sensors', []) | |
st.write(f"Sensors in selected building: {', '.join(sensors)}") | |
with col3: | |
st.header("Check Your HIN Number") | |
# config = Config(height=400, width=400, nodeHighlightBehavior=True, highlightColor="#F7A7A6", directed=True, collapsible=True) | |
if sensors: # Check if there are sensors to display | |
graph_store = TripleStore() | |
building_name = f"{data['buildings'][selected_index]['type']} ({selected_building_coords[0]}, {selected_building_coords[1]})" | |
# Iterate through each sensor and create a triple linking it to the building | |
for sensor in sensors: | |
sensor_id = f"Sensor: {sensor}" # Label for sensor nodes | |
# Correctly add the triple without named arguments | |
graph_store.add_triple(building_name, "has_sensor", sensor_id) | |
# Configuration for the graph visualization | |
agraph_config = Config(height=300, width=300, nodeHighlightBehavior=True, highlightColor="#F7A7A6", directed=True, collapsible=True) | |
# Display the graph | |
agraph(nodes=graph_store.getNodes(), edges=graph_store.getEdges(), config=agraph_config) | |
hin_number = st.text_input("Enter your HIN number:") | |
if hin_number: | |
st.write("HIN number details...") # Placeholder for actual HIN number check | |
with tab3: | |
st.header("Control Room") | |