Spaces:
Running
Running
label history appended and progress bar fixed
Browse files- components/dashboard_page.py +4 -0
- utils/auth.py +30 -13
components/dashboard_page.py
CHANGED
@@ -542,6 +542,10 @@ class DashboardPage:
|
|
542 |
fn=save_annotation_db_fn,
|
543 |
inputs=[self.tts_id, session_state, self.ann_sentence, self.applied_trims_list_state],
|
544 |
outputs=[] # save_annotation_db_fn does not return UI updates
|
|
|
|
|
|
|
|
|
545 |
)
|
546 |
|
547 |
event_chain = event_chain.then(
|
|
|
542 |
fn=save_annotation_db_fn,
|
543 |
inputs=[self.tts_id, session_state, self.ann_sentence, self.applied_trims_list_state],
|
544 |
outputs=[] # save_annotation_db_fn does not return UI updates
|
545 |
+
).then( # updating progress after save
|
546 |
+
fn=get_user_progress_fn,
|
547 |
+
inputs=[session_state],
|
548 |
+
outputs=self.header.progress_display
|
549 |
)
|
550 |
|
551 |
event_chain = event_chain.then(
|
utils/auth.py
CHANGED
@@ -82,7 +82,7 @@ class AuthService:
|
|
82 |
"sentence": row["tts_data"].sentence,
|
83 |
"annotated_sentence": (
|
84 |
row["annotation"].annotated_sentence
|
85 |
-
if row["annotation"]
|
86 |
else ""
|
87 |
),
|
88 |
"annotated_at": (
|
@@ -101,21 +101,38 @@ class AuthService:
|
|
101 |
|
102 |
session["dashboard_items"] = dashboard_items
|
103 |
|
104 |
-
#
|
|
|
105 |
if dashboard_items:
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
first_vals_for_ui = (
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
)
|
115 |
else:
|
116 |
-
first_vals_for_ui = ("", "", "", "")
|
117 |
|
118 |
-
log.info(f"User '{username}' logged in successfully.")
|
119 |
|
120 |
# ---------- خروجی نهایی برای Gradio ---------- #
|
121 |
return (
|
@@ -124,8 +141,8 @@ class AuthService:
|
|
124 |
gr.update(visible=True), # 2: داشبورد را نشان بده
|
125 |
gr.update(value=f"👋 Welcome, {annotator.name}!"), # 3
|
126 |
dashboard_items, # 4: items_state
|
127 |
-
|
128 |
-
*first_vals_for_ui, # 6-9: چهار فیلد نخست برای UI
|
129 |
)
|
130 |
|
131 |
# ───────────── LOGOUT ───────────── #
|
|
|
82 |
"sentence": row["tts_data"].sentence,
|
83 |
"annotated_sentence": (
|
84 |
row["annotation"].annotated_sentence
|
85 |
+
if row["annotation"] and row["annotation"].annotated_sentence is not None
|
86 |
else ""
|
87 |
),
|
88 |
"annotated_at": (
|
|
|
101 |
|
102 |
session["dashboard_items"] = dashboard_items
|
103 |
|
104 |
+
# --- Resume Logic: Find first unannotated or default to first/last item ---
|
105 |
+
initial_idx = 0
|
106 |
if dashboard_items:
|
107 |
+
first_unannotated_idx = -1
|
108 |
+
for i, item_data in enumerate(dashboard_items):
|
109 |
+
if not item_data["annotated_sentence"]: # Check if annotated_sentence is empty
|
110 |
+
first_unannotated_idx = i
|
111 |
+
break
|
112 |
+
|
113 |
+
if first_unannotated_idx != -1:
|
114 |
+
initial_idx = first_unannotated_idx
|
115 |
+
log.info(f"User '{username}' resuming at first unannotated item, index: {initial_idx} (ID: {dashboard_items[initial_idx]['id']})")
|
116 |
+
else: # All items are annotated or list is empty
|
117 |
+
initial_idx = len(dashboard_items) - 1 if dashboard_items else 0 # Go to the last item if all annotated, else 0
|
118 |
+
if dashboard_items:
|
119 |
+
log.info(f"User '{username}' has all items annotated or list is empty, starting at item index: {initial_idx} (ID: {dashboard_items[initial_idx]['id']})")
|
120 |
+
else: # No items assigned
|
121 |
+
log.info(f"User '{username}' has no items assigned, starting at index 0.")
|
122 |
+
|
123 |
+
# مقداردهی فیلدهای رکورد بر اساس initial_idx
|
124 |
+
if dashboard_items: # Check if list is not empty and initial_idx is valid
|
125 |
+
current_item_for_ui = dashboard_items[initial_idx]
|
126 |
first_vals_for_ui = (
|
127 |
+
current_item_for_ui["id"],
|
128 |
+
current_item_for_ui["filename"],
|
129 |
+
current_item_for_ui["sentence"],
|
130 |
+
current_item_for_ui["annotated_sentence"],
|
131 |
)
|
132 |
else:
|
133 |
+
first_vals_for_ui = ("", "", "", "") # id, filename, sentence, ann_sentence
|
134 |
|
135 |
+
log.info(f"User '{username}' logged in successfully. Initial index set to: {initial_idx}")
|
136 |
|
137 |
# ---------- خروجی نهایی برای Gradio ---------- #
|
138 |
return (
|
|
|
141 |
gr.update(visible=True), # 2: داشبورد را نشان بده
|
142 |
gr.update(value=f"👋 Welcome, {annotator.name}!"), # 3
|
143 |
dashboard_items, # 4: items_state
|
144 |
+
initial_idx, # 5: idx_state (Updated to determined initial_idx)
|
145 |
+
*first_vals_for_ui, # 6-9: چهار فیلد نخست برای UI (from item at initial_idx)
|
146 |
)
|
147 |
|
148 |
# ───────────── LOGOUT ───────────── #
|