Skip to content

Commit

Permalink
Refactor area limit handling and update UI text in Streamlit app
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijrajsharma committed Feb 22, 2025
1 parent 13588b9 commit 59f5a59
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from src.obe.app import download_buildings

MAX_AREA_KM2 = float(os.getenv("MAX_AREA_KM2", 5000))


def calculate_area_sqkm(gdf):
if gdf.crs is None:
Expand Down Expand Up @@ -71,8 +73,8 @@ def calculate_area_sqkm(gdf):
location = (
st.text_input(
"Country Name",
placeholder="e.g. Nepal",
help="Required for Microsoft Buildings",
placeholder="e.g. United States",
help="Required for Microsoft Buildings API",
)
if source == "microsoft"
else ""
Expand Down Expand Up @@ -146,21 +148,22 @@ def calculate_area_sqkm(gdf):

map_container = st.pydeck_chart(map_plot)

if area_sqkm > 5000:
if area_sqkm > MAX_AREA_KM2:
st.error(
"❌ Input area exceeds 5000 km². Please provide a smaller area."
f"❌ Input area exceeds {MAX_AREA_KM2:,} km² due to server restrictions. "
"For larger areas, please install and run locally: `pip install obe`"
)

except Exception as e:
st.info("Upload data or paste GeoJSON to see the preview")

with col2:
if "gdf" in locals():
# st.subheader("Area Statistics")
st.subheader("Area Statistics")
st.metric("Number of Features", len(gdf))
st.metric("Area", f"{area_sqkm:.2f} km²")

if area_sqkm <= 5000:
if area_sqkm <= MAX_AREA_KM2:
if st.button(
"🏗️ Extract Buildings", type="primary", use_container_width=True
):
Expand Down Expand Up @@ -219,7 +222,7 @@ def calculate_area_sqkm(gdf):

with open(output_path, "rb") as f:
st.download_button(
label=f"📥 Download {file_formats[file_format]}",
label=f"📥 Download",
data=f.read(),
file_name=output_path.name,
mime=f"application/{file_format}",
Expand Down

0 comments on commit 59f5a59

Please # to comment.