Spaces:
Sleeping
Sleeping
import streamlit as st | |
from PIL import Image | |
import os | |
st.title("Our History in Data") | |
# Set the global index path | |
global_index_path = "data/immaterial_index/figures_trends_R/results" | |
unseen_index_path = ( | |
"data/immaterial_index/figures_trends_R/figures_unseen/results_unseen" | |
) | |
unseen_capita_index_path = ( | |
"data/immaterial_index/figures_trends_R/figures_unseen/results_unseen/per_capita" | |
) | |
population_path = "data/population" | |
# Update image_paths using global_index_path | |
index_paths = { | |
"India": { | |
"global_index": f"{global_index_path}/india.png", | |
"unseen_index": f"{unseen_index_path}/india.png", | |
"unseen_index_capita": f"{unseen_capita_index_path}/india.png", | |
"population_index": f"{population_path}/Indian world.png", | |
}, | |
"Japan": { | |
"global_index": f"{global_index_path}/japan.png", | |
"unseen_index": f"{unseen_index_path}/japan.png", | |
"unseen_index_capita": f"{unseen_capita_index_path}/Japan.png", | |
"population_index": f"{population_path}/Japan.png", | |
}, | |
"France": { | |
"global_index": f"{global_index_path}/france.png", | |
"unseen_index": f"{unseen_index_path}/france.png", | |
"unseen_index_capita": f"{unseen_capita_index_path}/France.png", | |
"population_index": f"{population_path}/France.png", | |
}, | |
"Italy": { | |
"global_index": f"{global_index_path}/italy.png", | |
"unseen_index": f"{unseen_index_path}/italy.png", | |
"unseen_index_capita": f"{unseen_capita_index_path}/Italy.png", | |
"population_index": f"{population_path}/Italy.png", | |
}, | |
"Spain": { | |
"global_index": f"{global_index_path}/spain.png", | |
"unseen_index": f"{unseen_index_path}/spain.png", | |
"unseen_index_capita": f"{unseen_capita_index_path}/Spain.png", | |
"population_index": f"{population_path}/Spain.png", | |
}, | |
} | |
# Get the region names (keys) from the index_paths dictionary | |
regions = list(index_paths.keys()) | |
# Allow the user to select a region | |
selected_region = st.sidebar.selectbox("Region:", regions) | |
# Display the selected region's images vertically | |
if selected_region in index_paths: | |
for key, path in index_paths[selected_region].items(): | |
if os.path.exists(path): | |
if key == "global_index": | |
st.subheader("Global Index") | |
elif key == "unseen_index": | |
st.subheader("Unsee-Species Index") | |
elif key == "unseen_index_capita": | |
st.subheader("Unsee-Species per capita Index") | |
elif key == "population_index": | |
st.subheader("") | |
st.image(Image.open(path), caption=key.capitalize(), use_column_width=True) | |
else: | |
st.write(f"File for {key.capitalize()} does not exist.") | |
# Add more information or charts specific to India here | |
else: | |
st.write("Please select India as the region from the sidebar on the left.") | |