Spaces:
Running
Running
fixing login bug
Browse files- components/dashboard_page.py +181 -197
- components/review_dashboard_page.py +30 -30
- utils/auth.py +1 -1
- utils/database.py +4 -1
components/dashboard_page.py
CHANGED
@@ -152,54 +152,54 @@ class DashboardPage:
|
|
152 |
if not user_id:
|
153 |
return "Annotation Progress: N/A" # Added label
|
154 |
with get_db() as db:
|
155 |
-
try:
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
except Exception as e:
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
|
192 |
def download_voice_fn(filename_to_load, autoplay_on_load=True): # Autoplay here is for the btn_load_voice click
|
193 |
if not filename_to_load:
|
194 |
return None, None, gr.update(value=None, autoplay=False)
|
195 |
-
try:
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
except Exception as e:
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
|
204 |
def save_annotation_db_fn(current_tts_id, session, ann_text_to_save, applied_trims_list):
|
205 |
annotator_id = session.get("user_id")
|
@@ -208,62 +208,62 @@ class DashboardPage:
|
|
208 |
return # Modified: No return value
|
209 |
|
210 |
with get_db() as db:
|
211 |
-
try:
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
|
216 |
-
|
217 |
-
|
218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
)
|
220 |
-
db.add(
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
if annotation_obj.id is None: # If new annotation, flush to get ID
|
236 |
-
db.flush()
|
237 |
-
if annotation_obj.id is None:
|
238 |
-
gr.Error("Failed to get annotation ID for saving new trims.")
|
239 |
-
db.rollback(); return # Modified: No return value
|
240 |
-
|
241 |
-
for trim_info in applied_trims_list:
|
242 |
-
start_to_save_ms = trim_info['start_sec'] * 1000.0
|
243 |
-
end_to_save_ms = trim_info['end_sec'] * 1000.0
|
244 |
-
original_data_id_for_trim = current_tts_id
|
245 |
-
|
246 |
-
new_trim_db_obj = AudioTrim(
|
247 |
-
annotation_id=annotation_obj.id,
|
248 |
-
original_tts_data_id=original_data_id_for_trim,
|
249 |
-
start=start_to_save_ms,
|
250 |
-
end=end_to_save_ms,
|
251 |
-
)
|
252 |
-
db.add(new_trim_db_obj)
|
253 |
-
# No need to append to annotation_obj.audio_trims if cascade is working correctly
|
254 |
-
# but can be done explicitly: annotation_obj.audio_trims.append(new_trim_db_obj)
|
255 |
-
log.info(f"Saved {len(applied_trims_list)} trims for annotation {annotation_obj.id} (TTS ID: {current_tts_id}).")
|
256 |
-
else:
|
257 |
-
log.info(f"No trims applied for {current_tts_id}, any existing DB trims were cleared.")
|
258 |
-
|
259 |
-
db.commit()
|
260 |
-
gr.Info(f"Annotation for ID {current_tts_id} saved.")
|
261 |
-
# Removed 'return True'
|
262 |
-
except Exception as e:
|
263 |
-
db.rollback()
|
264 |
-
log.error(f"Failed to save annotation for {current_tts_id}: {e}") # Removed exc_info=True
|
265 |
-
sentry_sdk.capture_exception(e)
|
266 |
-
raise
|
267 |
|
268 |
def show_current_item_fn(items, idx, session):
|
269 |
initial_trims_list_sec = []
|
@@ -283,25 +283,25 @@ class DashboardPage:
|
|
283 |
|
284 |
if tts_data_id and annotator_id:
|
285 |
with get_db() as db:
|
286 |
-
try:
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
except Exception as e:
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
|
306 |
return (
|
307 |
current_item.get("id", ""), current_item.get("filename", ""),
|
@@ -320,54 +320,56 @@ class DashboardPage:
|
|
320 |
|
321 |
def load_all_items_fn(sess):
|
322 |
user_id = sess.get("user_id") # Use user_id for consistency with other functions
|
323 |
-
user_name = sess.get("
|
324 |
items_to_load = []
|
325 |
initial_idx = 0 # Default to 0
|
326 |
|
327 |
if not user_id:
|
328 |
-
|
|
|
|
|
329 |
empty_item_display_tuple = ("", "", "", "", None, None, None, [], self._convert_trims_to_df_data([]), gr.update(value=None, autoplay=False))
|
330 |
-
return [[], 0] + list(empty_item_display_tuple) + ["
|
331 |
|
332 |
if user_id:
|
333 |
with get_db() as db:
|
334 |
-
try:
|
335 |
-
|
336 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
for i, item_data in enumerate(items_to_load):
|
353 |
-
if not item_data["annotated"]:
|
354 |
-
first_unannotated_idx = i
|
355 |
-
break
|
356 |
-
|
357 |
-
if first_unannotated_idx != -1:
|
358 |
-
initial_idx = first_unannotated_idx
|
359 |
-
log.info(f"Resuming at first unannotated item, index: {initial_idx} (ID: {items_to_load[initial_idx]['id']})")
|
360 |
-
else: # All items are annotated
|
361 |
-
initial_idx = len(items_to_load) - 1
|
362 |
-
log.info(f"All items annotated, starting at last item, index: {initial_idx} (ID: {items_to_load[initial_idx]['id']})")
|
363 |
-
else: # No items assigned
|
364 |
-
initial_idx = 0
|
365 |
-
log.info("No items assigned to user, starting at index 0.")
|
366 |
-
|
367 |
-
except Exception as e:
|
368 |
-
log.error(f"Failed to load items or determine resume index for user {user_name}: {e}")
|
369 |
-
sentry_sdk.capture_exception(e)
|
370 |
-
raise
|
371 |
|
372 |
initial_ui_values_tuple = show_current_item_fn(items_to_load, initial_idx, sess)
|
373 |
progress_str = get_user_progress_fn(sess)
|
@@ -375,28 +377,17 @@ class DashboardPage:
|
|
375 |
|
376 |
def jump_by_data_id_fn(items, target_data_id_str, current_idx):
|
377 |
if not target_data_id_str: return current_idx
|
378 |
-
try:
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
except ValueError:
|
384 |
-
|
385 |
-
|
386 |
return current_idx
|
387 |
|
388 |
def delete_db_and_ui_fn(items, current_idx, session, original_audio_data_state):
|
389 |
-
# ... (ensure Annotation.audio_trims is used if deleting associated trims) ...
|
390 |
-
# This function already deletes annotation_obj.audio_trim, which will now be annotation_obj.audio_trims
|
391 |
-
# The cascade delete on the relationship should handle deleting all AudioTrim children.
|
392 |
-
# However, explicit deletion loop might be safer if cascade behavior is not fully trusted or for clarity.
|
393 |
-
# For now, relying on cascade from previous model update.
|
394 |
-
# If issues, add explicit loop:
|
395 |
-
# if annotation_obj.audio_trims:
|
396 |
-
# for trim_to_del in annotation_obj.audio_trims:
|
397 |
-
# db.delete(trim_to_del)
|
398 |
-
# annotation_obj.audio_trims = []
|
399 |
-
# ... rest of the function ...
|
400 |
new_ann_sentence = ""
|
401 |
new_trim_start_sec_ui = None # Changed from 0.0
|
402 |
new_trim_end_sec_ui = None # Changed from 0.0
|
@@ -426,28 +417,21 @@ class DashboardPage:
|
|
426 |
|
427 |
if tts_data_id_to_clear and annotator_id_for_clear:
|
428 |
with get_db() as db:
|
429 |
-
try:
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
else:
|
445 |
-
gr.Warning(f"No DB annotation found to delete for ID {tts_data_id_to_clear}.")
|
446 |
-
except Exception as e:
|
447 |
-
db.rollback()
|
448 |
-
log.error(f"Error deleting annotation from DB for {tts_data_id_to_clear}: {e}") # Removed exc_info=True
|
449 |
-
sentry_sdk.capture_exception(e)
|
450 |
-
raise
|
451 |
else:
|
452 |
gr.Error("Cannot clear/delete annotation from DB: Missing TTS ID or User ID.")
|
453 |
|
|
|
152 |
if not user_id:
|
153 |
return "Annotation Progress: N/A" # Added label
|
154 |
with get_db() as db:
|
155 |
+
# try:
|
156 |
+
# Total items assigned to the user
|
157 |
+
total_assigned_query = db.query(func.sum(AnnotationInterval.end_index - AnnotationInterval.start_index + 1)).filter(AnnotationInterval.annotator_id == user_id)
|
158 |
+
total_assigned_result = total_assigned_query.scalar()
|
159 |
+
total_assigned = total_assigned_result if total_assigned_result is not None else 0
|
160 |
+
|
161 |
+
# Count of non-empty annotations by this user within their assigned intervals
|
162 |
+
completed_count_query = db.query(func.count(Annotation.id)).join(
|
163 |
+
TTSData, Annotation.tts_data_id == TTSData.id
|
164 |
+
).join(
|
165 |
+
AnnotationInterval,
|
166 |
+
(AnnotationInterval.annotator_id == user_id) &
|
167 |
+
(TTSData.id >= AnnotationInterval.start_index) &
|
168 |
+
(TTSData.id <= AnnotationInterval.end_index)
|
169 |
+
).filter(
|
170 |
+
Annotation.annotator_id == user_id,
|
171 |
+
Annotation.annotated_sentence != None,
|
172 |
+
Annotation.annotated_sentence != ""
|
173 |
+
)
|
174 |
+
completed_count_result = completed_count_query.scalar()
|
175 |
+
completed_count = completed_count_result if completed_count_result is not None else 0
|
176 |
+
|
177 |
+
if total_assigned > 0:
|
178 |
+
percent = (completed_count / total_assigned) * 100
|
179 |
+
bar_length = 20 # Length of the progress bar
|
180 |
+
filled_length = int(bar_length * completed_count // total_assigned)
|
181 |
+
bar = 'β' * filled_length + 'β' * (bar_length - filled_length)
|
182 |
+
return f"Progress: {bar} {completed_count}/{total_assigned} ({percent:.1f}%)"
|
183 |
+
elif total_assigned == 0 and completed_count == 0: # Handles case where user has 0 assigned items initially
|
184 |
+
return "Progress: No items assigned yet."
|
185 |
+
else: # Should ideally not happen if logic is correct (e.g. completed > total_assigned)
|
186 |
+
return f"Annotation Progress: {completed_count}/{total_assigned} labeled"
|
187 |
+
# except Exception as e:
|
188 |
+
# log.error(f"Error fetching progress for user {user_id}: {e}")
|
189 |
+
# sentry_sdk.capture_exception(e)
|
190 |
+
# raise
|
191 |
|
192 |
def download_voice_fn(filename_to_load, autoplay_on_load=True): # Autoplay here is for the btn_load_voice click
|
193 |
if not filename_to_load:
|
194 |
return None, None, gr.update(value=None, autoplay=False)
|
195 |
+
# try:
|
196 |
+
log.info(f"Downloading voice: {filename_to_load}, Autoplay: {autoplay_on_load}")
|
197 |
+
sr, wav = LOADER.load_audio(filename_to_load)
|
198 |
+
return (sr, wav), (sr, wav.copy()), gr.update(value=(sr, wav), autoplay=autoplay_on_load)
|
199 |
+
# except Exception as e:
|
200 |
+
# log.error(f"GDrive download failed for {filename_to_load}: {e}")
|
201 |
+
# sentry_sdk.capture_exception(e)
|
202 |
+
# raise
|
203 |
|
204 |
def save_annotation_db_fn(current_tts_id, session, ann_text_to_save, applied_trims_list):
|
205 |
annotator_id = session.get("user_id")
|
|
|
208 |
return # Modified: No return value
|
209 |
|
210 |
with get_db() as db:
|
211 |
+
# try:
|
212 |
+
annotation_obj = db.query(Annotation).filter_by(
|
213 |
+
tts_data_id=current_tts_id, annotator_id=annotator_id
|
214 |
+
).options(orm.joinedload(Annotation.audio_trims)).first()
|
215 |
|
216 |
+
if not annotation_obj:
|
217 |
+
annotation_obj = Annotation(
|
218 |
+
tts_data_id=current_tts_id, annotator_id=annotator_id
|
219 |
+
)
|
220 |
+
db.add(annotation_obj)
|
221 |
+
|
222 |
+
annotation_obj.annotated_sentence = ann_text_to_save
|
223 |
+
annotation_obj.annotated_at = datetime.datetime.utcnow()
|
224 |
+
|
225 |
+
# --- Multi-trim handling ---
|
226 |
+
# 1. Delete existing trims for this annotation
|
227 |
+
if annotation_obj.audio_trims:
|
228 |
+
for old_trim in annotation_obj.audio_trims:
|
229 |
+
db.delete(old_trim)
|
230 |
+
annotation_obj.audio_trims = [] # Clear the collection
|
231 |
+
# db.flush() # Ensure deletes are processed before adds if issues arise
|
232 |
+
|
233 |
+
# 2. Add new trims from applied_trims_list
|
234 |
+
if applied_trims_list:
|
235 |
+
if annotation_obj.id is None: # If new annotation, flush to get ID
|
236 |
+
db.flush()
|
237 |
+
if annotation_obj.id is None:
|
238 |
+
gr.Error("Failed to get annotation ID for saving new trims.")
|
239 |
+
db.rollback(); return # Modified: No return value
|
240 |
+
|
241 |
+
for trim_info in applied_trims_list:
|
242 |
+
start_to_save_ms = trim_info['start_sec'] * 1000.0
|
243 |
+
end_to_save_ms = trim_info['end_sec'] * 1000.0
|
244 |
+
original_data_id_for_trim = current_tts_id
|
245 |
+
|
246 |
+
new_trim_db_obj = AudioTrim(
|
247 |
+
annotation_id=annotation_obj.id,
|
248 |
+
original_tts_data_id=original_data_id_for_trim,
|
249 |
+
start=start_to_save_ms,
|
250 |
+
end=end_to_save_ms,
|
251 |
)
|
252 |
+
db.add(new_trim_db_obj)
|
253 |
+
# No need to append to annotation_obj.audio_trims if cascade is working correctly
|
254 |
+
# but can be done explicitly: annotation_obj.audio_trims.append(new_trim_db_obj)
|
255 |
+
log.info(f"Saved {len(applied_trims_list)} trims for annotation {annotation_obj.id} (TTS ID: {current_tts_id}).")
|
256 |
+
else:
|
257 |
+
log.info(f"No trims applied for {current_tts_id}, any existing DB trims were cleared.")
|
258 |
+
|
259 |
+
db.commit()
|
260 |
+
gr.Info(f"Annotation for ID {current_tts_id} saved.")
|
261 |
+
# Removed 'return True'
|
262 |
+
# except Exception as e:
|
263 |
+
# db.rollback()
|
264 |
+
# log.error(f"Failed to save annotation for {current_tts_id}: {e}") # Removed exc_info=True
|
265 |
+
# sentry_sdk.capture_exception(e)
|
266 |
+
# raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
|
268 |
def show_current_item_fn(items, idx, session):
|
269 |
initial_trims_list_sec = []
|
|
|
283 |
|
284 |
if tts_data_id and annotator_id:
|
285 |
with get_db() as db:
|
286 |
+
# try:
|
287 |
+
existing_annotation = db.query(Annotation).filter_by(
|
288 |
+
tts_data_id=tts_data_id, annotator_id=annotator_id
|
289 |
+
).options(orm.joinedload(Annotation.audio_trims)).first() # Changed to audio_trims
|
290 |
+
if existing_annotation:
|
291 |
+
ann_text = existing_annotation.annotated_sentence or ""
|
292 |
+
if existing_annotation.audio_trims: # Check the collection
|
293 |
+
initial_trims_list_sec = [
|
294 |
+
{
|
295 |
+
'start_sec': trim.start / 1000.0,
|
296 |
+
'end_sec': trim.end / 1000.0
|
297 |
+
}
|
298 |
+
for trim in existing_annotation.audio_trims # Iterate over the collection
|
299 |
+
]
|
300 |
+
initial_trims_df_data = self._convert_trims_to_df_data(initial_trims_list_sec)
|
301 |
+
# except Exception as e:
|
302 |
+
# log.error(f"DB error in show_current_item_fn for TTS ID {tts_data_id}: {e}") # Removed exc_info=True
|
303 |
+
# sentry_sdk.capture_exception(e)
|
304 |
+
# raise
|
305 |
|
306 |
return (
|
307 |
current_item.get("id", ""), current_item.get("filename", ""),
|
|
|
320 |
|
321 |
def load_all_items_fn(sess):
|
322 |
user_id = sess.get("user_id") # Use user_id for consistency with other functions
|
323 |
+
user_name = sess.get("username") # Changed from "user_name" to "username" to match session key
|
324 |
items_to_load = []
|
325 |
initial_idx = 0 # Default to 0
|
326 |
|
327 |
if not user_id:
|
328 |
+
# No user logged in - return empty state without warning
|
329 |
+
# This is normal on initial app load before login
|
330 |
+
log.info("load_all_items_fn: user_id not found in session. Dashboard will display default state until login completes and data is refreshed.")
|
331 |
empty_item_display_tuple = ("", "", "", "", None, None, None, [], self._convert_trims_to_df_data([]), gr.update(value=None, autoplay=False))
|
332 |
+
return [[], 0] + list(empty_item_display_tuple) + [""]
|
333 |
|
334 |
if user_id:
|
335 |
with get_db() as db:
|
336 |
+
# try:
|
337 |
+
repo = AnnotatorWorkloadRepo(db)
|
338 |
+
raw_items = repo.get_tts_data_with_annotations_for_user_id(user_id, annotator_name_for_log=user_name)
|
339 |
+
|
340 |
+
items_to_load = [
|
341 |
+
{
|
342 |
+
"id": item["tts_data"].id,
|
343 |
+
"filename": item["tts_data"].filename,
|
344 |
+
"sentence": item["tts_data"].sentence,
|
345 |
+
"annotated": item["annotation"] is not None and (item["annotation"].annotated_sentence is not None and item["annotation"].annotated_sentence != "")
|
346 |
+
}
|
347 |
+
for item in raw_items
|
348 |
+
]
|
349 |
+
log.info(f"Loaded {len(items_to_load)} items for user {user_name} (ID: {user_id})")
|
350 |
+
|
351 |
+
# --- Resume Logic: Find first unannotated or last item ---
|
352 |
+
if items_to_load:
|
353 |
+
first_unannotated_idx = -1
|
354 |
+
for i, item_data in enumerate(items_to_load):
|
355 |
+
if not item_data["annotated"]:
|
356 |
+
first_unannotated_idx = i
|
357 |
+
break
|
358 |
|
359 |
+
if first_unannotated_idx != -1:
|
360 |
+
initial_idx = first_unannotated_idx
|
361 |
+
log.info(f"Resuming at first unannotated item, index: {initial_idx} (ID: {items_to_load[initial_idx]['id']})")
|
362 |
+
else: # All items are annotated
|
363 |
+
initial_idx = len(items_to_load) - 1
|
364 |
+
log.info(f"All items annotated, starting at last item, index: {initial_idx} (ID: {items_to_load[initial_idx]['id']})")
|
365 |
+
else: # No items assigned
|
366 |
+
initial_idx = 0
|
367 |
+
log.info("No items assigned to user, starting at index 0.")
|
368 |
+
|
369 |
+
# except Exception as e:
|
370 |
+
# log.error(f"Failed to load items or determine resume index for user {user_name}: {e}")
|
371 |
+
# sentry_sdk.capture_exception(e)
|
372 |
+
# raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
373 |
|
374 |
initial_ui_values_tuple = show_current_item_fn(items_to_load, initial_idx, sess)
|
375 |
progress_str = get_user_progress_fn(sess)
|
|
|
377 |
|
378 |
def jump_by_data_id_fn(items, target_data_id_str, current_idx):
|
379 |
if not target_data_id_str: return current_idx
|
380 |
+
# try:
|
381 |
+
target_id = int(target_data_id_str)
|
382 |
+
for i, item_dict in enumerate(items):
|
383 |
+
if item_dict.get("id") == target_id: return i
|
384 |
+
gr.Warning(f"Data ID {target_id} not found in your assigned items.")
|
385 |
+
# except ValueError:
|
386 |
+
# sentry_sdk.capture_exception()
|
387 |
+
# gr.Warning(f"Invalid Data ID format: {target_data_id_str}")
|
388 |
return current_idx
|
389 |
|
390 |
def delete_db_and_ui_fn(items, current_idx, session, original_audio_data_state):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
391 |
new_ann_sentence = ""
|
392 |
new_trim_start_sec_ui = None # Changed from 0.0
|
393 |
new_trim_end_sec_ui = None # Changed from 0.0
|
|
|
417 |
|
418 |
if tts_data_id_to_clear and annotator_id_for_clear:
|
419 |
with get_db() as db:
|
420 |
+
# try:
|
421 |
+
annotation_obj = db.query(Annotation).filter_by(
|
422 |
+
tts_data_id=tts_data_id_to_clear, annotator_id=annotator_id_for_clear
|
423 |
+
).options(orm.joinedload(Annotation.audio_trims)).first() # Ensure audio_trims are loaded
|
424 |
+
if annotation_obj:
|
425 |
+
db.delete(annotation_obj)
|
426 |
+
db.commit()
|
427 |
+
gr.Info(f"Annotation and associated trims for ID {tts_data_id_to_clear} deleted from DB.")
|
428 |
+
else:
|
429 |
+
gr.Warning(f"No DB annotation found to delete for ID {tts_data_id_to_clear}.")
|
430 |
+
# except Exception as e:
|
431 |
+
# db.rollback()
|
432 |
+
# log.error(f"Error deleting annotation from DB for {tts_data_id_to_clear}: {e}") # Removed exc_info=True
|
433 |
+
# sentry_sdk.capture_exception(e)
|
434 |
+
# raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
435 |
else:
|
436 |
gr.Error("Cannot clear/delete annotation from DB: Missing TTS ID or User ID.")
|
437 |
|
components/review_dashboard_page.py
CHANGED
@@ -120,36 +120,36 @@ class ReviewDashboardPage:
|
|
120 |
def download_voice_fn(filename_to_load):
|
121 |
if not filename_to_load:
|
122 |
return None, None, gr.update(value=None, autoplay=False)
|
123 |
-
try:
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
except TimeoutError as e:
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
except ConnectionError as e:
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
except FileNotFoundError as e:
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
except Exception as e:
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
|
154 |
def load_review_items_fn(session):
|
155 |
user_id = session.get("user_id")
|
|
|
120 |
def download_voice_fn(filename_to_load):
|
121 |
if not filename_to_load:
|
122 |
return None, None, gr.update(value=None, autoplay=False)
|
123 |
+
# try:
|
124 |
+
log.info(f"Downloading voice for review: {filename_to_load}")
|
125 |
+
# Show progress to user
|
126 |
+
# gr.Info(f"Loading audio file: {filename_to_load}")
|
127 |
+
|
128 |
+
sr, wav = LOADER.load_audio(filename_to_load)
|
129 |
+
|
130 |
+
log.info(f"Successfully loaded audio: {filename_to_load} (SR: {sr}, Length: {len(wav)} samples)")
|
131 |
+
# gr.Info(f"β
Audio loaded successfully!")
|
132 |
+
|
133 |
+
return (sr, wav), (sr, wav.copy()), gr.update(value=(sr, wav), autoplay=True)
|
134 |
+
# except TimeoutError as e:
|
135 |
+
# log.error(f"Audio download timeout for {filename_to_load}: {e}")
|
136 |
+
# sentry_sdk.capture_exception(e)
|
137 |
+
# raise
|
138 |
+
# except ConnectionError as e:
|
139 |
+
# log.error(f"Audio download connection error for {filename_to_load}: {e}")
|
140 |
+
# sentry_sdk.capture_exception(e)
|
141 |
+
# gr.Error(f"π Connection error loading audio: {filename_to_load}. Please check your internet connection.")
|
142 |
+
# return None, None, gr.update(value=None, autoplay=False)
|
143 |
+
# except FileNotFoundError as e:
|
144 |
+
# log.error(f"Audio file not found for {filename_to_load}: {e}")
|
145 |
+
# sentry_sdk.capture_exception(e)
|
146 |
+
# gr.Error(f"π Audio file not found: {filename_to_load}")
|
147 |
+
# return None, None, gr.update(value=None, autoplay=False)
|
148 |
+
# except Exception as e:
|
149 |
+
# log.error(f"Audio download failed for {filename_to_load}: {e}")
|
150 |
+
# sentry_sdk.capture_exception(e)
|
151 |
+
# gr.Error(f"β Failed to load audio: {filename_to_load}. Error: {e}")
|
152 |
+
# return None, None, gr.update(value=None, autoplay=False)
|
153 |
|
154 |
def load_review_items_fn(session):
|
155 |
user_id = session.get("user_id")
|
utils/auth.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from utils.logger import Logger
|
3 |
from utils.database import get_db
|
4 |
from data.repository.annotator_repo import AnnotatorRepo
|
5 |
from data.repository.annotator_workload_repo import AnnotatorWorkloadRepo
|
6 |
from utils.security import verify_password
|
7 |
from config import conf
|
8 |
-
import time # Add this import
|
9 |
|
10 |
log = Logger()
|
11 |
|
|
|
1 |
import gradio as gr
|
2 |
+
import time
|
3 |
from utils.logger import Logger
|
4 |
from utils.database import get_db
|
5 |
from data.repository.annotator_repo import AnnotatorRepo
|
6 |
from data.repository.annotator_workload_repo import AnnotatorWorkloadRepo
|
7 |
from utils.security import verify_password
|
8 |
from config import conf
|
|
|
9 |
|
10 |
log = Logger()
|
11 |
|
utils/database.py
CHANGED
@@ -51,7 +51,8 @@ def get_db():
|
|
51 |
# except Exception as e:
|
52 |
# db.rollback()
|
53 |
# log.error(f"Database error: {e}")
|
54 |
-
#
|
|
|
55 |
# finally:
|
56 |
db.close()
|
57 |
|
@@ -65,3 +66,5 @@ def initialize_database():
|
|
65 |
log.info("Tables created successfully")
|
66 |
# except Exception as e:
|
67 |
# log.error(f"Table creation failed: {e}")
|
|
|
|
|
|
51 |
# except Exception as e:
|
52 |
# db.rollback()
|
53 |
# log.error(f"Database error: {e}")
|
54 |
+
# sentry_sdk.capture_exception(e) # Add Sentry logging
|
55 |
+
# raise # Re-raise for debugging
|
56 |
# finally:
|
57 |
db.close()
|
58 |
|
|
|
66 |
log.info("Tables created successfully")
|
67 |
# except Exception as e:
|
68 |
# log.error(f"Table creation failed: {e}")
|
69 |
+
# sentry_sdk.capture_exception(e)
|
70 |
+
# raise
|