Spaces:
Sleeping
Sleeping
full screen map
Browse files- src/streamlit_app.py +25 -37
src/streamlit_app.py
CHANGED
|
@@ -27,7 +27,8 @@ st.markdown(
|
|
| 27 |
--muted-bg: #fafafa;
|
| 28 |
--border: #e9ecef;
|
| 29 |
}
|
| 30 |
-
|
|
|
|
| 31 |
h1, h2, h3 {letter-spacing: .2px;}
|
| 32 |
hr {border-color: var(--border);}
|
| 33 |
.kpi {background: var(--muted-bg); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px;}
|
|
@@ -37,6 +38,8 @@ hr {border-color: var(--border);}
|
|
| 37 |
.caption-muted {color: #6c757d; font-size: 0.9rem;}
|
| 38 |
.section-card {background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px; padding: 1rem;}
|
| 39 |
.stButton>button {border-radius: 10px;}
|
|
|
|
|
|
|
| 40 |
</style>
|
| 41 |
""",
|
| 42 |
unsafe_allow_html=True,
|
|
@@ -216,26 +219,7 @@ except Exception:
|
|
| 216 |
|
| 217 |
trap_default = trap_id_from_qp or (traps_df["trap_id"].iloc[0] if not traps_df.empty else "T001")
|
| 218 |
|
| 219 |
-
# ----------
|
| 220 |
-
st.sidebar.header("Settings")
|
| 221 |
-
model = st.sidebar.selectbox(
|
| 222 |
-
"Vision model",
|
| 223 |
-
[
|
| 224 |
-
"meta-llama/Llama-Vision-Free",
|
| 225 |
-
"meta-llama/Llama-3.2-11B-Vision-Instruct-Turbo",
|
| 226 |
-
"Qwen/Qwen2.5-VL-72B-Instruct",
|
| 227 |
-
],
|
| 228 |
-
index=0,
|
| 229 |
-
)
|
| 230 |
-
with st.sidebar.expander("Photo tips", expanded=True):
|
| 231 |
-
st.markdown(
|
| 232 |
-
"- Place strip within the calibration rectangle \n"
|
| 233 |
-
"- Bright, even light; avoid glare/shadows \n"
|
| 234 |
-
"- Keep phone parallel to the card \n"
|
| 235 |
-
"- Retake if blurry",
|
| 236 |
-
)
|
| 237 |
-
|
| 238 |
-
# ---------- Main Layout ----------
|
| 239 |
left, right = st.columns([1, 1], gap="large")
|
| 240 |
|
| 241 |
# ----- Left: Capture & Count -----
|
|
@@ -317,7 +301,9 @@ with left:
|
|
| 317 |
file_name=fname, mime="image/png",
|
| 318 |
key=f"dl_{fname}")
|
| 319 |
|
| 320 |
-
# ----- Right: Dashboard -----
|
|
|
|
|
|
|
| 321 |
with right:
|
| 322 |
st.markdown("### ๐ Weekly dashboard")
|
| 323 |
with st.container(border=True):
|
|
@@ -398,12 +384,10 @@ with right:
|
|
| 398 |
show = latest_week.sort_values("count", ascending=False).reset_index(drop=True)
|
| 399 |
st.dataframe(show, use_container_width=True)
|
| 400 |
|
| 401 |
-
#
|
| 402 |
if not traps_df.empty and {"lat", "lon"}.issubset(traps_df.columns):
|
| 403 |
map_df = traps_df.merge(latest_week[["trap_id", "count"]], on="trap_id", how="left").fillna({"count": 0})
|
| 404 |
-
deck = None
|
| 405 |
|
| 406 |
-
# Build deck object
|
| 407 |
if not map_df.empty:
|
| 408 |
lat0 = float(map_df["lat"].mean())
|
| 409 |
lon0 = float(map_df["lon"].mean())
|
|
@@ -468,13 +452,16 @@ with right:
|
|
| 468 |
view = pdk.ViewState(latitude=lat0, longitude=lon0, zoom=13.5)
|
| 469 |
deck = pdk.Deck(map_style=None, initial_view_state=view,
|
| 470 |
layers=[osm, hex_layer, points, labels],
|
| 471 |
-
tooltip={"text": "Trap {trap_id}\nCount: {count}\n{label}"})
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
|
|
|
|
|
|
|
|
|
| 478 |
<div class="legend">
|
| 479 |
<div><b>Legend:</b></div>
|
| 480 |
<div><span class="dot" style="background:#5CB85C"></span> Low (1โ9)</div>
|
|
@@ -484,11 +471,12 @@ with right:
|
|
| 484 |
<div style="margin-left:auto;opacity:.7">Hex height/color = total eggs in area</div>
|
| 485 |
</div>
|
| 486 |
""",
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
|
|
|
| 492 |
|
| 493 |
# ---------- Footer ----------
|
| 494 |
st.markdown("<hr/>", unsafe_allow_html=True)
|
|
|
|
| 27 |
--muted-bg: #fafafa;
|
| 28 |
--border: #e9ecef;
|
| 29 |
}
|
| 30 |
+
/* widen the page a bit and keep nice margins */
|
| 31 |
+
.block-container {padding-top: 1.1rem; padding-bottom: 2rem; max-width: 96vw;}
|
| 32 |
h1, h2, h3 {letter-spacing: .2px;}
|
| 33 |
hr {border-color: var(--border);}
|
| 34 |
.kpi {background: var(--muted-bg); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px;}
|
|
|
|
| 38 |
.caption-muted {color: #6c757d; font-size: 0.9rem;}
|
| 39 |
.section-card {background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px; padding: 1rem;}
|
| 40 |
.stButton>button {border-radius: 10px;}
|
| 41 |
+
/* full-width map container with subtle margins */
|
| 42 |
+
.map-wrap {margin: 1.25rem 0 0.5rem 0;}
|
| 43 |
</style>
|
| 44 |
""",
|
| 45 |
unsafe_allow_html=True,
|
|
|
|
| 219 |
|
| 220 |
trap_default = trap_id_from_qp or (traps_df["trap_id"].iloc[0] if not traps_df.empty else "T001")
|
| 221 |
|
| 222 |
+
# ---------- Main 2-column Layout ----------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
left, right = st.columns([1, 1], gap="large")
|
| 224 |
|
| 225 |
# ----- Left: Capture & Count -----
|
|
|
|
| 301 |
file_name=fname, mime="image/png",
|
| 302 |
key=f"dl_{fname}")
|
| 303 |
|
| 304 |
+
# ----- Right: Dashboard (KPIs / charts / table) -----
|
| 305 |
+
# We only compute 'deck' (the map) here, but we will RENDER it later in a full-width section.
|
| 306 |
+
deck = None
|
| 307 |
with right:
|
| 308 |
st.markdown("### ๐ Weekly dashboard")
|
| 309 |
with st.container(border=True):
|
|
|
|
| 384 |
show = latest_week.sort_values("count", ascending=False).reset_index(drop=True)
|
| 385 |
st.dataframe(show, use_container_width=True)
|
| 386 |
|
| 387 |
+
# Build deck object for the map (we'll show it in full width later)
|
| 388 |
if not traps_df.empty and {"lat", "lon"}.issubset(traps_df.columns):
|
| 389 |
map_df = traps_df.merge(latest_week[["trap_id", "count"]], on="trap_id", how="left").fillna({"count": 0})
|
|
|
|
| 390 |
|
|
|
|
| 391 |
if not map_df.empty:
|
| 392 |
lat0 = float(map_df["lat"].mean())
|
| 393 |
lon0 = float(map_df["lon"].mean())
|
|
|
|
| 452 |
view = pdk.ViewState(latitude=lat0, longitude=lon0, zoom=13.5)
|
| 453 |
deck = pdk.Deck(map_style=None, initial_view_state=view,
|
| 454 |
layers=[osm, hex_layer, points, labels],
|
| 455 |
+
tooltip={"text": "Trap {trap_id}\\nCount: {count}\\n{label}"})
|
| 456 |
+
|
| 457 |
+
# ---------- Full-width Map (render after both columns) ----------
|
| 458 |
+
if deck:
|
| 459 |
+
st.markdown("## ๐บ๏ธ Kolkata hotspots (OpenStreetMap)")
|
| 460 |
+
st.markdown('<div class="map-wrap">', unsafe_allow_html=True)
|
| 461 |
+
# Make the map the star: full width + generous height
|
| 462 |
+
st.pydeck_chart(deck, use_container_width=True, height=680)
|
| 463 |
+
st.markdown(
|
| 464 |
+
"""
|
| 465 |
<div class="legend">
|
| 466 |
<div><b>Legend:</b></div>
|
| 467 |
<div><span class="dot" style="background:#5CB85C"></span> Low (1โ9)</div>
|
|
|
|
| 471 |
<div style="margin-left:auto;opacity:.7">Hex height/color = total eggs in area</div>
|
| 472 |
</div>
|
| 473 |
""",
|
| 474 |
+
unsafe_allow_html=True,
|
| 475 |
+
)
|
| 476 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 477 |
+
else:
|
| 478 |
+
# Optional hint if map didn't render
|
| 479 |
+
st.info("Add lat/lon columns to traps.csv and have counts for the selected week to view the map.")
|
| 480 |
|
| 481 |
# ---------- Footer ----------
|
| 482 |
st.markdown("<hr/>", unsafe_allow_html=True)
|