Spaces:
Sleeping
Sleeping
swaraj commited on
Commit Β·
ac71316
1
Parent(s): 7abe61d
chnages
Browse files
model_interface/a_17_grapes_count.py
CHANGED
|
@@ -426,6 +426,16 @@ def grapes_count():
|
|
| 426 |
})
|
| 427 |
|
| 428 |
# ββ STABLE two-column layout (always rendered, prevents shaking) βββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 429 |
col_input, col_output = st.columns(2)
|
| 430 |
|
| 431 |
with col_input:
|
|
@@ -434,18 +444,25 @@ def grapes_count():
|
|
| 434 |
|
| 435 |
with col_output:
|
| 436 |
st.subheader("π Predicted Output")
|
|
|
|
|
|
|
|
|
|
| 437 |
if st.session_state["result"] is not None:
|
| 438 |
out_img = st.session_state["result"]["image"]
|
| 439 |
if os.path.exists(out_img):
|
| 440 |
-
|
| 441 |
else:
|
| 442 |
-
#
|
| 443 |
-
|
| 444 |
-
"""
|
| 445 |
-
<div style="
|
| 446 |
-
|
| 447 |
-
border-radius:8px;
|
|
|
|
|
|
|
|
|
|
| 448 |
Click <strong>Run</strong> to see prediction here
|
|
|
|
| 449 |
</div>
|
| 450 |
""",
|
| 451 |
unsafe_allow_html=True,
|
|
|
|
| 426 |
})
|
| 427 |
|
| 428 |
# ββ STABLE two-column layout (always rendered, prevents shaking) βββ
|
| 429 |
+
# Read the input image dimensions so the placeholder matches exactly.
|
| 430 |
+
_probe = cv2.imread(image_path)
|
| 431 |
+
if _probe is not None:
|
| 432 |
+
_ih, _iw = _probe.shape[:2]
|
| 433 |
+
# Columns are ~50% of page width. Use aspect-ratio CSS so the
|
| 434 |
+
# placeholder box is the same proportional height as the real image.
|
| 435 |
+
_aspect_pct = round((_ih / _iw) * 100, 2)
|
| 436 |
+
else:
|
| 437 |
+
_aspect_pct = 75.0 # safe fallback (4:3)
|
| 438 |
+
|
| 439 |
col_input, col_output = st.columns(2)
|
| 440 |
|
| 441 |
with col_input:
|
|
|
|
| 444 |
|
| 445 |
with col_output:
|
| 446 |
st.subheader("π Predicted Output")
|
| 447 |
+
# Use a single st.empty() slot β Streamlit replaces its content
|
| 448 |
+
# in-place on rerun, so the surrounding layout never shifts.
|
| 449 |
+
out_slot = st.empty()
|
| 450 |
if st.session_state["result"] is not None:
|
| 451 |
out_img = st.session_state["result"]["image"]
|
| 452 |
if os.path.exists(out_img):
|
| 453 |
+
out_slot.image(out_img, use_container_width=True)
|
| 454 |
else:
|
| 455 |
+
# Aspect-ratio box matches the input image height exactly.
|
| 456 |
+
out_slot.markdown(
|
| 457 |
+
f"""
|
| 458 |
+
<div style="position:relative;width:100%;
|
| 459 |
+
padding-top:{_aspect_pct}%;
|
| 460 |
+
background:#f0f2f6;border-radius:8px;">
|
| 461 |
+
<div style="position:absolute;inset:0;display:flex;
|
| 462 |
+
align-items:center;justify-content:center;
|
| 463 |
+
color:#888;font-size:15px;">
|
| 464 |
Click <strong>Run</strong> to see prediction here
|
| 465 |
+
</div>
|
| 466 |
</div>
|
| 467 |
""",
|
| 468 |
unsafe_allow_html=True,
|