Cryptic commited on
Commit
394213a
·
1 Parent(s): 363abbd
Files changed (1) hide show
  1. app.py +23 -8
app.py CHANGED
@@ -6,6 +6,7 @@ import numpy as np
6
  from transformers import pipeline
7
  import torch
8
  import soundfile as sf
 
9
 
10
  # Page configuration
11
  st.set_page_config(page_title="Audio Processing App", layout="wide")
@@ -24,12 +25,12 @@ def load_models():
24
 
25
  models = {
26
  'transcriber': pipeline("automatic-speech-recognition",
27
- model="openai/whisper-tiny.en",
28
- device=device,
29
- chunk_length_s=30), # Process in 30-second chunks
30
  'summarizer': pipeline("summarization",
31
- model="sshleifer/distilbart-cnn-12-6",
32
- device=device)
33
  }
34
  return models, None
35
  except Exception as e:
@@ -148,9 +149,23 @@ def main():
148
  st.session_state.models_loaded = True
149
  st.session_state.models = models
150
 
151
- # File uploader with clear instructions
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  st.write("Upload an audio file of your lecture (supported formats: WAV, MP3, M4A, FLAC)")
153
  st.write("Note: Processing long audio files may take several minutes.")
 
154
  uploaded_file = st.file_uploader("Choose a file", type=["wav", "mp3", "m4a", "flac"])
155
 
156
  if uploaded_file is not None:
@@ -171,7 +186,7 @@ def main():
171
 
172
  st.subheader("📌 Summary")
173
  st.write(results['summary'])
174
-
175
  except Exception as e:
176
  st.error(f"An unexpected error occurred: {str(e)}")
177
 
@@ -184,4 +199,4 @@ def main():
184
  pass
185
 
186
  if __name__ == "__main__":
187
- main()
 
6
  from transformers import pipeline
7
  import torch
8
  import soundfile as sf
9
+ import json # For JSON response
10
 
11
  # Page configuration
12
  st.set_page_config(page_title="Audio Processing App", layout="wide")
 
25
 
26
  models = {
27
  'transcriber': pipeline("automatic-speech-recognition",
28
+ model="openai/whisper-tiny.en",
29
+ device=device,
30
+ chunk_length_s=30), # Process in 30-second chunks
31
  'summarizer': pipeline("summarization",
32
+ model="sshleifer/distilbart-cnn-12-6",
33
+ device=device)
34
  }
35
  return models, None
36
  except Exception as e:
 
149
  st.session_state.models_loaded = True
150
  st.session_state.models = models
151
 
152
+ # Check if an audio file was uploaded via API
153
+ query_params = st.experimental_get_query_params()
154
+ if "file" in query_params:
155
+ audio_file_path = query_params["file"][0] # This should be the path to the uploaded audio file
156
+
157
+ # Process the audio
158
+ results = process_audio(audio_file_path, st.session_state.models)
159
+
160
+ if results:
161
+ # Return the results as JSON
162
+ st.json(results)
163
+ return # Exit the function early to avoid further processing in the UI
164
+
165
+ # Normal Streamlit UI flow for file upload
166
  st.write("Upload an audio file of your lecture (supported formats: WAV, MP3, M4A, FLAC)")
167
  st.write("Note: Processing long audio files may take several minutes.")
168
+
169
  uploaded_file = st.file_uploader("Choose a file", type=["wav", "mp3", "m4a", "flac"])
170
 
171
  if uploaded_file is not None:
 
186
 
187
  st.subheader("📌 Summary")
188
  st.write(results['summary'])
189
+
190
  except Exception as e:
191
  st.error(f"An unexpected error occurred: {str(e)}")
192
 
 
199
  pass
200
 
201
  if __name__ == "__main__":
202
+ main()