chrissoria commited on
Commit
c7403e5
·
1 Parent(s): 67ce2bc

Add estimated time and animated status indicator for category extraction

Browse files
Files changed (1) hide show
  1. app.py +22 -3
app.py CHANGED
@@ -850,7 +850,24 @@ with col_input:
850
  else:
851
  model_source = get_model_source(model)
852
 
853
- with st.spinner("Extracting categories..."):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
854
  start_time = time.time()
855
 
856
  extract_kwargs = {
@@ -872,13 +889,15 @@ with col_input:
872
  processing_time = time.time() - start_time
873
 
874
  if categories:
 
875
  st.session_state.extracted_categories = categories
876
  st.session_state.task_mode = "manual"
877
- st.success(f"Extracted {len(categories)} categories in {processing_time:.1f}s")
878
  st.rerun()
879
  else:
880
- st.error("No categories were extracted")
 
881
  except Exception as e:
 
882
  st.error(f"Error: {str(e)}")
883
 
884
  # Category inputs (shown for manual mode or after extraction)
 
850
  else:
851
  model_source = get_model_source(model)
852
 
853
+ # Calculate estimated time based on input size
854
+ num_items = len(input_data) if isinstance(input_data, list) else 1
855
+ if input_type_selected == "pdf":
856
+ # PDFs take longer - estimate ~5s per page
857
+ total_pages = sum(count_pdf_pages(p) for p in (input_data if isinstance(input_data, list) else [input_data]))
858
+ est_seconds = total_pages * 5
859
+ elif input_type_selected == "image":
860
+ # Images ~4s each
861
+ est_seconds = num_items * 4
862
+ else:
863
+ # Text ~2s per item, but batched
864
+ est_seconds = max(10, num_items * 0.5)
865
+
866
+ est_time_str = f"{est_seconds:.0f}s" if est_seconds < 60 else f"{est_seconds/60:.1f}m"
867
+
868
+ # Animated status indicator
869
+ with st.status(f"Extracting categories (est. {est_time_str})...", expanded=True) as status:
870
+ st.write("Analyzing your data to discover categories...")
871
  start_time = time.time()
872
 
873
  extract_kwargs = {
 
889
  processing_time = time.time() - start_time
890
 
891
  if categories:
892
+ status.update(label=f"Extracted {len(categories)} categories in {processing_time:.1f}s", state="complete", expanded=False)
893
  st.session_state.extracted_categories = categories
894
  st.session_state.task_mode = "manual"
 
895
  st.rerun()
896
  else:
897
+ status.update(label="No categories extracted", state="error")
898
+ st.error("No categories were extracted from the data")
899
  except Exception as e:
900
+ status.update(label="Extraction failed", state="error")
901
  st.error(f"Error: {str(e)}")
902
 
903
  # Category inputs (shown for manual mode or after extraction)