|
|
@@ -64,13 +64,25 @@ st.sidebar.slider(
|
|
|
on_change=update_confidence
|
|
|
)
|
|
|
|
|
|
+# Helper to reset results when files change
|
|
|
+def reset_single_results():
|
|
|
+ st.session_state.last_detection = None
|
|
|
+
|
|
|
+def reset_batch_results():
|
|
|
+ st.session_state.last_batch_results = None
|
|
|
+
|
|
|
# --- Tabs ---
|
|
|
tab1, tab2, tab3 = st.tabs(["Single Analysis", "Batch Processing", "Similarity Search"])
|
|
|
|
|
|
# --- Tab 1: Single Analysis ---
|
|
|
with tab1:
|
|
|
st.subheader("Analyze Single Bunch")
|
|
|
- uploaded_file = st.file_uploader("Upload a bunch image...", type=["jpg", "jpeg", "png"], key="single")
|
|
|
+ uploaded_file = st.file_uploader(
|
|
|
+ "Upload a bunch image...",
|
|
|
+ type=["jpg", "jpeg", "png"],
|
|
|
+ key="single",
|
|
|
+ on_change=reset_single_results
|
|
|
+ )
|
|
|
|
|
|
if uploaded_file:
|
|
|
# State initialization
|
|
|
@@ -97,6 +109,9 @@ with tab1:
|
|
|
# SIDE-BY-SIDE ANALYTICAL VIEW
|
|
|
col_left, col_right = st.columns(2)
|
|
|
|
|
|
+ # Fetch data once
|
|
|
+ data = st.session_state.last_detection
|
|
|
+
|
|
|
with col_left:
|
|
|
st.image(uploaded_file, caption="Original Photo", width='stretch')
|
|
|
|
|
|
@@ -110,10 +125,19 @@ with tab1:
|
|
|
annotated_img_rgb = annotated_img[:, :, ::-1]
|
|
|
st.image(annotated_img_rgb, caption="AI Analytical View (X-Ray)", width='stretch')
|
|
|
|
|
|
+ st.write("### 📈 Manager's Dashboard")
|
|
|
+ m_col1, m_col2, m_col3 = st.columns(3)
|
|
|
+ with m_col1:
|
|
|
+ st.metric("Total Bunches", data.get('total_count', 0))
|
|
|
+ with m_col2:
|
|
|
+ st.metric("Healthy (Ripe)", data['industrial_summary'].get('Ripe', 0))
|
|
|
+ with m_col3:
|
|
|
+ abnormal = data['industrial_summary'].get('Abnormal', 0)
|
|
|
+ st.metric("Abnormal Alerts", abnormal, delta=-abnormal, delta_color="inverse")
|
|
|
+
|
|
|
col1, col2 = st.columns([1.5, 1]) # Keep original col structure for summary below
|
|
|
|
|
|
with col2:
|
|
|
- data = st.session_state.last_detection
|
|
|
with st.container(border=True):
|
|
|
st.write("### 🏷️ Detection Results")
|
|
|
if not data['detections']:
|
|
|
@@ -228,7 +252,8 @@ with tab2:
|
|
|
"Upload multiple images...",
|
|
|
type=["jpg", "jpeg", "png"],
|
|
|
accept_multiple_files=True,
|
|
|
- key=f"batch_{st.session_state.batch_uploader_key}"
|
|
|
+ key=f"batch_{st.session_state.batch_uploader_key}",
|
|
|
+ on_change=reset_batch_results
|
|
|
)
|
|
|
|
|
|
with col_batch2:
|