czyoung commited on
Commit
7c32767
·
verified ·
1 Parent(s): aa23222

Update to include pipeline in session_state

Browse files
Files changed (1) hide show
  1. state.py +9 -2
state.py CHANGED
@@ -57,6 +57,7 @@ def init_session_state():
57
  "speakerWaveforms": {}, # {filename: (waveform_tensor, sample_rate)}
58
  "globalRenames": [], # [{"name": str, "speakers": ["file: SPEAKER_##", ...]}]
59
  "analyzeAllToggle": False,
 
60
  }
61
  for key, value in defaults.items():
62
  if key not in st.session_state:
@@ -489,7 +490,7 @@ def load_demo_multi(demo_paths):
489
  st.session_state.analyzeAllToggle = True
490
 
491
 
492
- def run_analysis_loop(file_names, file_paths_dict, pipeline):
493
  """Process only new (not yet analyzed) files and populate session state."""
494
  import time
495
  import utils as _utils
@@ -516,6 +517,9 @@ def run_analysis_loop(file_names, file_paths_dict, pipeline):
516
 
517
  totalFiles = len(pending)
518
 
 
 
 
519
  for i, fname in enumerate(pending):
520
  fpath = file_paths_dict.get(fname, "")
521
  ext = fpath.lower()
@@ -538,6 +542,8 @@ def run_analysis_loop(file_names, file_paths_dict, pipeline):
538
  with st.spinner(f"Analyzing {i+1}/{totalFiles}"):
539
  analyze(fname)
540
 
 
 
541
  st.success(f"Analyzed {totalFiles} new file(s) in {time.time() - start_time:.1f}s")
542
  st.session_state.analyzeAllToggle = False
543
  # Rotate uploader key to clear the file uploader widget
@@ -598,7 +604,8 @@ def analyze(inFileName):
598
  ]
599
  printV("Loaded results", 4)
600
 
601
- noVoice, oneVoice, multiVoice = su.calcSpeakingTypes(currAnnotation, currTotalTime)
 
602
  sumNoVoice = su.sumTimes(noVoice)
603
  sumOneVoice = su.sumTimes(oneVoice)
604
  sumMultiVoice = su.sumTimes(multiVoice)
 
57
  "speakerWaveforms": {}, # {filename: (waveform_tensor, sample_rate)}
58
  "globalRenames": [], # [{"name": str, "speakers": ["file: SPEAKER_##", ...]}]
59
  "analyzeAllToggle": False,
60
+ "pipeline": None, # Sonogram object
61
  }
62
  for key, value in defaults.items():
63
  if key not in st.session_state:
 
490
  st.session_state.analyzeAllToggle = True
491
 
492
 
493
+ def run_analysis_loop(file_names, file_paths_dict):
494
  """Process only new (not yet analyzed) files and populate session state."""
495
  import time
496
  import utils as _utils
 
517
 
518
  totalFiles = len(pending)
519
 
520
+ # Pull pipeline and move to device for inference
521
+ pipeline = st.session_state.pipeline
522
+ pipline.to(pipeline.device)
523
  for i, fname in enumerate(pending):
524
  fpath = file_paths_dict.get(fname, "")
525
  ext = fpath.lower()
 
542
  with st.spinner(f"Analyzing {i+1}/{totalFiles}"):
543
  analyze(fname)
544
 
545
+ # Return to cpu
546
+ pipeline.to('cpu')
547
  st.success(f"Analyzed {totalFiles} new file(s) in {time.time() - start_time:.1f}s")
548
  st.session_state.analyzeAllToggle = False
549
  # Rotate uploader key to clear the file uploader widget
 
604
  ]
605
  printV("Loaded results", 4)
606
 
607
+ pipeline = st.session_state.pipeline
608
+ noVoice, oneVoice, multiVoice = su.calcSpeakingTypes(pipeline,currAnnotation, currTotalTime)
609
  sumNoVoice = su.sumTimes(noVoice)
610
  sumOneVoice = su.sumTimes(oneVoice)
611
  sumMultiVoice = su.sumTimes(multiVoice)