czyoung commited on
Commit
85b7ab1
·
verified ·
1 Parent(s): 0eeae78

Updated to use model

Browse files
Files changed (1) hide show
  1. app.py +62 -12
app.py CHANGED
@@ -14,6 +14,10 @@ import os
14
  import shutil
15
  import pandas as pd
16
  import plotly.express as px
 
 
 
 
17
 
18
  PARQUET_DATASET_DIR = Path("parquet_dataset")
19
  PARQUET_DATASET_DIR.mkdir(parents=True,exist_ok=True)
@@ -23,6 +27,18 @@ sample_data = [f"CHEM1402_gt/24F_CHEM1402_Night_Class_Week_{i}_gt.rttm" for i in
23
 
24
  scheduler = ps.ParquetScheduler(repo_id="Sonogram/SampleDataset")
25
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  # Store results for viewing and further processing
27
  if 'results' not in st.session_state:
28
  st.session_state.results = []
@@ -52,7 +68,23 @@ def save_data(
52
  # Send to scheduler
53
  scheduler.append(data)
54
 
55
- st.set_page_config(layout="wide")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  st.title("Lecturer Support Tool")
57
 
58
  uploaded_file_paths = st.file_uploader("Upload an audio of classroom activity to analyze", accept_multiple_files=True)
@@ -84,21 +116,39 @@ if uploaded_file_paths is not None:
84
  while (len(st.session_state.summaries) < len(valid_files)):
85
  st.session_state.summaries.append([])
86
  st.info(f'{len(valid_files)} valid files: {[fi.name for fi in valid_files]}')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  for i, tab in enumerate(audio_tabs):
88
  if tab.button("Analyze Audio",key=f"button_{i}"):
89
- if uploaded_file is None:
90
- tab.error('Upload a file first!')
91
- else:
92
- # Process
93
- # Pretend to take time as an example
94
  with st.spinner(text='NOT ACTUALLY ANALYZING, JUST A FILLER ANIMATION'):
95
  time.sleep(1)
96
- st.success('Done')
97
-
98
- # RTTM load as filler
99
- speakerList, annotations = su.loadAudioRTTM(sample_data[i])
100
- st.session_state.results[i] = (speakerList,annotations)
101
- st.session_state.summaries[i] = []
 
 
102
 
103
  if len(st.session_state.results) > i and len(st.session_state.summaries) > i and len(st.session_state.results[i]) > 0:
104
  with st.spinner(text='Loading results...'):
 
14
  import shutil
15
  import pandas as pd
16
  import plotly.express as px
17
+ import torch
18
+ from pyannote.audio import Pipeline
19
+ from pyannote.core import Annotation, Segment
20
+ from df.enhance import enhance, init_df
21
 
22
  PARQUET_DATASET_DIR = Path("parquet_dataset")
23
  PARQUET_DATASET_DIR.mkdir(parents=True,exist_ok=True)
 
27
 
28
  scheduler = ps.ParquetScheduler(repo_id="Sonogram/SampleDataset")
29
 
30
+ secondDifference = config['secondDifference']
31
+ gainWindow = config['gainWindow']
32
+ minimumGain = config['minimumGain']
33
+ maximumGain = config['maximumGain']
34
+ attenLimDB = config['attenLimDB']
35
+
36
+ # Instantiate and prepare model for training.
37
+ dfModel, dfState, _ = init_df(model_base_dir="DeepFilterNet3")
38
+ #dfModel.to(torch.device("cuda:0"))
39
+ pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization-3.1")
40
+ #pipeline.to(torch.device("cuda:1"))
41
+
42
  # Store results for viewing and further processing
43
  if 'results' not in st.session_state:
44
  st.session_state.results = []
 
68
  # Send to scheduler
69
  scheduler.append(data)
70
 
71
+ def processFile(filePath):
72
+ global attenLimDb
73
+ global gainWindow
74
+ global minimumGain
75
+ global maximumGain
76
+ waveformList, sampleRate = su.splitIntoTimeSegments(filePath)
77
+ enhancedWaveformList = []
78
+ for w in waveformList:
79
+ newW = enhance(dfModel,dfState,w,atten_lim_db=attenLimDB)#.detach().cpu()
80
+ enhancedWaveformList.append(newW)
81
+ waveformEnhanced = combineWaveforms(enhancedWaveformList)
82
+ waveform_gain_adjusted = equalizeVolume()(waveformEnhanced,sample_rate,gainWindow,minimumGain,maximumGain)
83
+ annotations = pipeline({"waveform": waveformEnhanced, "sample_rate": sample_rate})
84
+ speakerList = su.annotationToSpeakerList(annotations)
85
+ return speakerList, annotations
86
+
87
+ #st.set_page_config(layout="wide")
88
  st.title("Lecturer Support Tool")
89
 
90
  uploaded_file_paths = st.file_uploader("Upload an audio of classroom activity to analyze", accept_multiple_files=True)
 
116
  while (len(st.session_state.summaries) < len(valid_files)):
117
  st.session_state.summaries.append([])
118
  st.info(f'{len(valid_files)} valid files: {[fi.name for fi in valid_files]}')
119
+
120
+ if tab.button("Analyze All Audio",key=f"button_all"):
121
+ if len(valid_files) == 0:
122
+ tab.error('Upload file(s) first!')
123
+ else:
124
+ totalFiles = len(valid_files)
125
+ for i in range(totalFiles):
126
+ with st.spinner(text=f'Analyzing File {i+1} of {totalFiles}'):
127
+ # Text files use sample data
128
+ if file_paths[i].endswith('.txt'):
129
+ time.sleep(1)
130
+ # RTTM load as filler
131
+ speakerList, annotations = su.loadAudioRTTM(sample_data[i])
132
+ st.session_state.results[i] = (speakerList,annotations)
133
+ st.session_state.summaries[i] = []
134
+ else:
135
+ st.session_state.results[i] = processFile(file_paths[i])
136
+ st.session_state.summaries[i] = []
137
+
138
  for i, tab in enumerate(audio_tabs):
139
  if tab.button("Analyze Audio",key=f"button_{i}"):
140
+ # Text files use sample data
141
+ if file_paths[i].endswith('.txt'):
 
 
 
142
  with st.spinner(text='NOT ACTUALLY ANALYZING, JUST A FILLER ANIMATION'):
143
  time.sleep(1)
144
+ # RTTM load as filler
145
+ speakerList, annotations = su.loadAudioRTTM(sample_data[i])
146
+ st.session_state.results[i] = (speakerList,annotations)
147
+ st.session_state.summaries[i] = []
148
+ else:
149
+ with st.spinner(text='Analyzing File'):
150
+ st.session_state.results[i] = processFile(file_paths[i])
151
+ st.session_state.summaries[i] = []
152
 
153
  if len(st.session_state.results) > i and len(st.session_state.summaries) > i and len(st.session_state.results[i]) > 0:
154
  with st.spinner(text='Loading results...'):