Prasanna Balaprakash Claude commited on
Commit
3600a7e
·
1 Parent(s): 5dd864d

Update optimization animation to use st.empty() loop pattern

Browse files

- Restructured animation loop to update st.empty() containers within single script execution
- Added status container showing step progress during optimization
- Re-enabled animation mode (ENABLE_ANIMATION = True) for real-time progress tracking
- Improved code organization for animation state management
- Updated comments in objective_progress.py for clarity

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (2) hide show
  1. app.py +47 -46
  2. components/objective_progress.py +2 -2
app.py CHANGED
@@ -68,10 +68,8 @@ if 'active_tab' not in st.session_state:
68
  st.session_state.active_tab = 0 # Default to Optimization tab
69
 
70
  # Animation mode - set to False for Hugging Face Spaces (instant results)
71
- # Set to True for local demos with 10-second animation
72
- # NOTE: Due to Streamlit's execution model, real-time animation is unreliable
73
- # Setting to False for instant, reliable results
74
- ENABLE_ANIMATION = False # Set to True to attempt 10-second animation (may not work consistently)
75
 
76
  # Render sidebar and get config
77
  sidebar_config = render_sidebar()
@@ -323,18 +321,24 @@ with tabs[0]:
323
 
324
  st.markdown("---")
325
 
326
- # Create placeholders for real-time animation
327
- objective_placeholder = st.empty()
328
- divider1 = st.empty()
329
- progress_placeholder = st.empty()
330
- divider2 = st.empty()
331
- trajectory_placeholder = st.empty()
332
-
333
- # Run animation loop for real-time updates
334
  if st.session_state.optimization_running:
 
 
 
 
 
 
 
 
 
335
  for step in range(st.session_state.progress_step, 21):
336
- # Update objective progress
337
- with objective_placeholder.container():
 
 
 
 
338
  render_objective_progress(
339
  budget_hours=sidebar_config['estimated_hours'],
340
  is_running=True,
@@ -342,11 +346,11 @@ with tabs[0]:
342
  current_step=step
343
  )
344
 
345
- with divider1:
346
  st.markdown("---")
347
 
348
  # Update progress chart
349
- with progress_placeholder.container():
350
  render_progress_chart(
351
  budget_hours=sidebar_config['estimated_hours'],
352
  is_running=True,
@@ -354,57 +358,54 @@ with tabs[0]:
354
  current_step=step
355
  )
356
 
357
- with divider2:
358
  st.markdown("---")
359
 
360
  # Update search trajectory
361
- with trajectory_placeholder.container():
362
  render_search_trajectory(
363
  is_running=True,
364
  current_step=step
365
  )
366
 
367
- # Store current step
368
  st.session_state.progress_step = step
369
 
370
- # Sleep for animation (this creates the 10-second total duration)
371
  if ENABLE_ANIMATION and step < 20:
372
  time.sleep(0.5)
373
 
374
- # Mark as complete after loop
375
  st.session_state.progress_step = 20
376
  st.session_state.optimization_running = False
377
  st.session_state.optimization_completed = True
 
 
 
 
378
  st.rerun()
379
- else:
380
- # Show final state when completed
381
- with objective_placeholder.container():
382
- if st.session_state.optimization_completed:
383
- render_objective_progress(
384
- budget_hours=sidebar_config['estimated_hours'],
385
- is_running=False,
386
- selected_objectives=sidebar_config['objectives']
387
- )
388
 
389
- with divider1:
390
- if st.session_state.optimization_completed:
391
- st.markdown("---")
 
 
 
 
392
 
393
- with progress_placeholder.container():
394
- if st.session_state.optimization_completed:
395
- render_progress_chart(
396
- budget_hours=sidebar_config['estimated_hours'],
397
- is_running=False,
398
- enable_animation=ENABLE_ANIMATION
399
- )
400
 
401
- with divider2:
402
- if st.session_state.optimization_completed:
403
- st.markdown("---")
 
 
 
 
404
 
405
- with trajectory_placeholder.container():
406
- if st.session_state.optimization_completed:
407
- render_search_trajectory(is_running=False)
408
 
409
  # Results Tab
410
  with tabs[1]:
 
68
  st.session_state.active_tab = 0 # Default to Optimization tab
69
 
70
  # Animation mode - set to False for Hugging Face Spaces (instant results)
71
+ # Set to True for local demos with real-time progress animation
72
+ ENABLE_ANIMATION = True # Set to False for HF Spaces deployment (instant results)
 
 
73
 
74
  # Render sidebar and get config
75
  sidebar_config = render_sidebar()
 
321
 
322
  st.markdown("---")
323
 
324
+ # Run optimization animation loop using st.empty() for real-time updates
 
 
 
 
 
 
 
325
  if st.session_state.optimization_running:
326
+ # Create empty containers for progressive updates
327
+ status_container = st.empty()
328
+ objective_container = st.empty()
329
+ divider1_container = st.empty()
330
+ progress_container = st.empty()
331
+ divider2_container = st.empty()
332
+ trajectory_container = st.empty()
333
+
334
+ # Animate through all 20 steps
335
  for step in range(st.session_state.progress_step, 21):
336
+ # Update status
337
+ with status_container:
338
+ st.info(f"⚙️ **Optimizing...** Step {step}/20 ({int(step/20*100)}%)")
339
+
340
+ # Update objective progress charts
341
+ with objective_container.container():
342
  render_objective_progress(
343
  budget_hours=sidebar_config['estimated_hours'],
344
  is_running=True,
 
346
  current_step=step
347
  )
348
 
349
+ with divider1_container:
350
  st.markdown("---")
351
 
352
  # Update progress chart
353
+ with progress_container.container():
354
  render_progress_chart(
355
  budget_hours=sidebar_config['estimated_hours'],
356
  is_running=True,
 
358
  current_step=step
359
  )
360
 
361
+ with divider2_container:
362
  st.markdown("---")
363
 
364
  # Update search trajectory
365
+ with trajectory_container.container():
366
  render_search_trajectory(
367
  is_running=True,
368
  current_step=step
369
  )
370
 
371
+ # Update session state
372
  st.session_state.progress_step = step
373
 
374
+ # Sleep to create animation effect (allows browser to render)
375
  if ENABLE_ANIMATION and step < 20:
376
  time.sleep(0.5)
377
 
378
+ # Mark as complete
379
  st.session_state.progress_step = 20
380
  st.session_state.optimization_running = False
381
  st.session_state.optimization_completed = True
382
+
383
+ # Clear status and show completion
384
+ status_container.success("🎉 **Optimization Complete!**")
385
+ time.sleep(1)
386
  st.rerun()
 
 
 
 
 
 
 
 
 
387
 
388
+ elif st.session_state.optimization_completed:
389
+ # Show final results
390
+ render_objective_progress(
391
+ budget_hours=sidebar_config['estimated_hours'],
392
+ is_running=False,
393
+ selected_objectives=sidebar_config['objectives']
394
+ )
395
 
396
+ st.markdown("---")
 
 
 
 
 
 
397
 
398
+ render_progress_chart(
399
+ budget_hours=sidebar_config['estimated_hours'],
400
+ is_running=False,
401
+ enable_animation=ENABLE_ANIMATION
402
+ )
403
+
404
+ st.markdown("---")
405
 
406
+ render_search_trajectory(
407
+ is_running=False
408
+ )
409
 
410
  # Results Tab
411
  with tabs[1]:
components/objective_progress.py CHANGED
@@ -14,12 +14,12 @@ def render_objective_progress(budget_hours=2, is_running=False, selected_objecti
14
  df = generate_all_objectives_progress(budget_hours)
15
  total_rows = len(df)
16
 
17
- # If optimization is "running", only show partial data
18
  if is_running:
19
  # Use provided current_step or get from session state
20
  if current_step is None:
21
  current_step = st.session_state.get('progress_step', 1)
22
- # Always show at least 1 row so charts are visible from the start
23
  display_rows = max(1, min(current_step, total_rows))
24
  df = df.iloc[:display_rows]
25
 
 
14
  df = generate_all_objectives_progress(budget_hours)
15
  total_rows = len(df)
16
 
17
+ # If optimization is "running", only show partial data based on current progress
18
  if is_running:
19
  # Use provided current_step or get from session state
20
  if current_step is None:
21
  current_step = st.session_state.get('progress_step', 1)
22
+ # Show data up to current step (1-20)
23
  display_rows = max(1, min(current_step, total_rows))
24
  df = df.iloc[:display_rows]
25