فهرست منبع

UI enhancements.

Dr-Swopt 2 هفته پیش
والد
کامیت
69f3182263
2فایلهای تغییر یافته به همراه33 افزوده شده و 5 حذف شده
  1. 28 3
      demo_app.py
  2. 5 2
      src/api/main.py

+ 28 - 3
demo_app.py

@@ -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:

+ 5 - 2
src/api/main.py

@@ -90,6 +90,7 @@ async def analyze_with_health_metrics(file: UploadFile = File(...)):
     return {
         "status": "success",
         "current_threshold": current_conf,
+        "total_count": sum(summary.values()),
         "industrial_summary": summary,
         "detections": detections
     }
@@ -170,12 +171,14 @@ async def process_batch(files: List[UploadFile] = File(...)):
         # 4. Process Batch Use Case with error handling for cloud services
         try:
             record_ids = analyze_batch_use_case.execute(batch_results)
+            total_records = len(record_ids)
             return {
                 "status": "success", 
-                "processed_count": len(record_ids), 
+                "processed_count": total_records, 
+                "total_count": sum(total_summary.values()),
                 "record_ids": record_ids,
                 "industrial_summary": total_summary,
-                "message": f"Successfully processed {len(record_ids)} bunches"
+                "message": f"Successfully processed {total_records} images and identified {sum(total_summary.values())} bunches"
             }
         except RuntimeError as e:
             return {