aseelflihan commited on
Commit
22fb240
Β·
verified Β·
1 Parent(s): 6d8fa3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -35
app.py CHANGED
@@ -130,14 +130,13 @@ def step_1_upload_and_process():
130
  reset_session()
131
  st.rerun()
132
 
133
- # --- Audio Processing Function (with robust stateless logic) ---
134
  def process_audio():
135
  if not st.session_state.audio_file:
136
  st.error("No audio file found.")
137
  return
138
 
139
  tmp_file_path = None
140
- log_to_browser_console("--- INFO: Starting audio processing. ---")
141
  try:
142
  with tempfile.NamedTemporaryFile(delete=False, suffix=Path(st.session_state.audio_file.name).suffix) as tmp_file:
143
  st.session_state.audio_file.seek(0)
@@ -145,55 +144,43 @@ def process_audio():
145
  tmp_file_path = tmp_file.name
146
 
147
  processor = AUDIO_PROCESSOR_CLASS()
148
- with st.spinner("🎀 Transcribing audio..."):
149
- transcription_result = processor.transcribe_audio(tmp_file_path)
150
-
151
- if "Error:" in transcription_result or not transcription_result:
152
- st.error(f"Transcription failed: {transcription_result}")
153
- return
154
 
155
- # --- AGGRESSIVE DEBUGGING FOR TIMESTAMPS ---
156
- log_to_browser_console("--- DEBUG: Attempting to extract word timestamps... ---")
157
  word_timestamps = []
158
- try:
159
- with st.spinner("πŸ” Extracting timestamps..."):
160
- if hasattr(processor, 'get_word_timestamps'):
161
- word_timestamps = processor.get_word_timestamps(tmp_file_path)
162
- else:
163
- log_to_browser_console("--- WARNING: processor object has no 'get_word_timestamps' method. ---")
164
-
165
- # This is the most important log. It will tell us the truth.
166
- log_to_browser_console(f"--- CRITICAL: Extracted {len(word_timestamps)} timestamps. ---")
167
-
168
- if not word_timestamps:
169
- st.warning("CRITICAL WARNING: No word timestamps were extracted from the audio processor. The list is empty. SYLT embedding will fail.")
170
- log_to_browser_console("--- ERROR: The list of word_timestamps received from audio_processor is EMPTY. ---")
171
- else:
172
- # Log the first 3 entries to see if the data format is correct
173
- log_to_browser_console(f"--- DEBUG: Sample of extracted timestamps: {json.dumps(word_timestamps[:3])} ---")
174
 
175
- except Exception as e:
176
- st.error(f"A fatal error occurred inside 'get_word_timestamps': {e}")
177
- log_to_browser_console(f"--- FATAL ERROR during get_word_timestamps call: {traceback.format_exc()} ---")
178
- word_timestamps = [] # Ensure it's an empty list on failure
179
- # --- END OF DEBUGGING BLOCK ---
 
 
 
 
 
180
 
181
  st.session_state.audio_file.seek(0)
182
  audio_bytes = st.session_state.audio_file.read()
183
 
184
  st.session_state.transcription_data = {
185
- 'text': transcription_result,
186
  'word_timestamps': word_timestamps,
187
  'audio_bytes': audio_bytes,
188
  'original_suffix': Path(st.session_state.audio_file.name).suffix
189
  }
190
- st.session_state.edited_text = transcription_result
191
  st.session_state.step = 2
192
- st.success("πŸŽ‰ Audio processing complete!")
193
 
194
  except Exception as e:
195
- st.error(f"An unexpected error occurred during the main processing flow!")
196
  st.exception(e)
 
197
  finally:
198
  if tmp_file_path and os.path.exists(tmp_file_path):
199
  os.unlink(tmp_file_path)
@@ -202,6 +189,7 @@ def process_audio():
202
  st.rerun()
203
 
204
 
 
205
  # --- Step 2: Review and Customize ---
206
  def step_2_review_and_customize():
207
  st.header("Step 2: Review & Customize")
 
130
  reset_session()
131
  st.rerun()
132
 
 
133
  def process_audio():
134
  if not st.session_state.audio_file:
135
  st.error("No audio file found.")
136
  return
137
 
138
  tmp_file_path = None
139
+ log_to_browser_console("--- INFO: Starting audio processing flow. ---")
140
  try:
141
  with tempfile.NamedTemporaryFile(delete=False, suffix=Path(st.session_state.audio_file.name).suffix) as tmp_file:
142
  st.session_state.audio_file.seek(0)
 
144
  tmp_file_path = tmp_file.name
145
 
146
  processor = AUDIO_PROCESSOR_CLASS()
 
 
 
 
 
 
147
 
 
 
148
  word_timestamps = []
149
+ # The audio_processor now returns both data and logs
150
+ with st.spinner("🎀 Performing AI processing (Transcription & Timestamps)..."):
151
+ word_timestamps, processor_logs = processor.get_word_timestamps(tmp_file_path)
152
+
153
+ # Log everything that happened inside the processor to the browser
154
+ log_to_browser_console(processor_logs)
 
 
 
 
 
 
 
 
 
 
155
 
156
+ # Check if the final result is empty and show a warning
157
+ if not word_timestamps:
158
+ st.warning("Could not generate timestamps. Check the browser console (F12) for detailed error logs.")
159
+
160
+ # We still need the full text for the editor, even if timestamps fail
161
+ # This is a simplified way; a better way would be for get_word_timestamps to also return the text
162
+ full_text = " ".join([d['word'] for d in word_timestamps])
163
+ if not full_text and processor_logs:
164
+ # Try to find a fallback text from logs if available
165
+ full_text = "Transcription failed. Please check logs and edit text manually."
166
 
167
  st.session_state.audio_file.seek(0)
168
  audio_bytes = st.session_state.audio_file.read()
169
 
170
  st.session_state.transcription_data = {
171
+ 'text': full_text, # Use the text we derived
172
  'word_timestamps': word_timestamps,
173
  'audio_bytes': audio_bytes,
174
  'original_suffix': Path(st.session_state.audio_file.name).suffix
175
  }
176
+ st.session_state.edited_text = full_text
177
  st.session_state.step = 2
178
+ st.success("πŸŽ‰ AI processing complete! Please review the results.")
179
 
180
  except Exception as e:
181
+ st.error("An unexpected error occurred in the main processing flow!")
182
  st.exception(e)
183
+ log_to_browser_console(f"--- FATAL ERROR in app.py's process_audio: {traceback.format_exc()} ---")
184
  finally:
185
  if tmp_file_path and os.path.exists(tmp_file_path):
186
  os.unlink(tmp_file_path)
 
189
  st.rerun()
190
 
191
 
192
+
193
  # --- Step 2: Review and Customize ---
194
  def step_2_review_and_customize():
195
  st.header("Step 2: Review & Customize")