Spaces:
Runtime error
Runtime error
GitHub Actions commited on
Commit Β·
80eb3dd
1
Parent(s): 5ae8b4c
π Automated sync from GitHub
Browse files- src/ux_agent.py +24 -12
src/ux_agent.py
CHANGED
|
@@ -657,10 +657,15 @@ class AgentUX:
|
|
| 657 |
self.last_pending_count = count
|
| 658 |
return f"### {label} - Review Submissions from React Games", sound
|
| 659 |
|
| 660 |
-
def admin_approve_pending(self,
|
| 661 |
try:
|
| 662 |
df = pd.read_csv(self.PENDING_FILE)
|
| 663 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 664 |
|
| 665 |
# π’ Use the edited text instead of the original row data
|
| 666 |
final_utt = edited_utt if edited_utt else row["Utterance"]
|
|
@@ -685,7 +690,7 @@ class AgentUX:
|
|
| 685 |
}
|
| 686 |
threading.Thread(target=self.trust.stamp_on_chain, args=(payload,), daemon=True).start()
|
| 687 |
|
| 688 |
-
df.drop(
|
| 689 |
self.sync_pending_queue(direction="up")
|
| 690 |
|
| 691 |
audio_to_delete = row.get("Audio")
|
|
@@ -705,12 +710,17 @@ class AgentUX:
|
|
| 705 |
except Exception as e:
|
| 706 |
return f"β Approval failed: {e}"
|
| 707 |
|
| 708 |
-
def admin_reject_pending(self,
|
| 709 |
try:
|
| 710 |
df = pd.read_csv(self.PENDING_FILE)
|
| 711 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 712 |
|
| 713 |
-
df.drop(
|
| 714 |
self.sync_pending_queue(direction="up")
|
| 715 |
|
| 716 |
audio_to_delete = row.get("Audio")
|
|
@@ -991,7 +1001,8 @@ class AgentUX:
|
|
| 991 |
# π’ NEW: Editable Textboxes for Admin Corrections
|
| 992 |
gr.Markdown("#### βοΈ Edit Selected Entry Before Minting")
|
| 993 |
with gr.Row():
|
| 994 |
-
|
|
|
|
| 995 |
edit_utt = gr.Textbox(label="Utterance", interactive=True)
|
| 996 |
edit_dialect = gr.Textbox(label="Dialect / Language", interactive=True)
|
| 997 |
edit_clar = gr.Textbox(label="Clarification / Meaning", interactive=True)
|
|
@@ -1154,23 +1165,24 @@ class AgentUX:
|
|
| 1154 |
idx = evt.index[0]
|
| 1155 |
row = df.iloc[idx]
|
| 1156 |
audio_path = row.get("Audio")
|
|
|
|
| 1157 |
utt = str(row.get("Utterance", ""))
|
| 1158 |
clar = str(row.get("Clarification", ""))
|
| 1159 |
tone = str(row.get("Tone", ""))
|
| 1160 |
dialect = str(row.get("Dialect", ""))
|
| 1161 |
-
return audio_path,
|
| 1162 |
except:
|
| 1163 |
-
return None,
|
| 1164 |
|
| 1165 |
filter_dialect.change(self.get_pending_dataframe, inputs=[filter_dialect], outputs=[pending_df])
|
| 1166 |
btn_refresh.click(self.get_pending_dataframe, inputs=[filter_dialect], outputs=[pending_df])
|
| 1167 |
|
| 1168 |
# π’ FIX: Fill the textboxes when a row is clicked
|
| 1169 |
-
pending_df.select(select_pending_row, [pending_df], [pending_audio_player,
|
| 1170 |
|
| 1171 |
# π’ FIX: Pass the edited textboxes to the approval function, then auto-refresh the table
|
| 1172 |
-
btn_appr_p.click(self.admin_approve_pending, inputs=[
|
| 1173 |
-
btn_rejt_p.click(self.admin_reject_pending, inputs=[
|
| 1174 |
btn_clear_pending.click(self.admin_clear_all_pending, outputs=[audit_log]).then(self.get_pending_dataframe, inputs=[filter_dialect], outputs=[pending_df])
|
| 1175 |
|
| 1176 |
def trigger_recovery():
|
|
|
|
| 657 |
self.last_pending_count = count
|
| 658 |
return f"### {label} - Review Submissions from React Games", sound
|
| 659 |
|
| 660 |
+
def admin_approve_pending(self, timestamp, orig_utt, edited_utt, edited_dialect, edited_clar, edited_tone, trimmed_audio_path):
|
| 661 |
try:
|
| 662 |
df = pd.read_csv(self.PENDING_FILE)
|
| 663 |
+
match = df[(df["Timestamp"] == timestamp) & (df["Utterance"] == orig_utt)]
|
| 664 |
+
if len(match) == 0:
|
| 665 |
+
return "β Approval failed: Entry not found in pending database."
|
| 666 |
+
|
| 667 |
+
index_in_csv = match.index[0]
|
| 668 |
+
row = df.loc[index_in_csv]
|
| 669 |
|
| 670 |
# π’ Use the edited text instead of the original row data
|
| 671 |
final_utt = edited_utt if edited_utt else row["Utterance"]
|
|
|
|
| 690 |
}
|
| 691 |
threading.Thread(target=self.trust.stamp_on_chain, args=(payload,), daemon=True).start()
|
| 692 |
|
| 693 |
+
df.drop(index_in_csv).to_csv(self.PENDING_FILE, index=False)
|
| 694 |
self.sync_pending_queue(direction="up")
|
| 695 |
|
| 696 |
audio_to_delete = row.get("Audio")
|
|
|
|
| 710 |
except Exception as e:
|
| 711 |
return f"β Approval failed: {e}"
|
| 712 |
|
| 713 |
+
def admin_reject_pending(self, timestamp, orig_utt):
|
| 714 |
try:
|
| 715 |
df = pd.read_csv(self.PENDING_FILE)
|
| 716 |
+
match = df[(df["Timestamp"] == timestamp) & (df["Utterance"] == orig_utt)]
|
| 717 |
+
if len(match) == 0:
|
| 718 |
+
return "β Rejection failed: Entry not found."
|
| 719 |
+
|
| 720 |
+
index_in_csv = match.index[0]
|
| 721 |
+
row = df.loc[index_in_csv]
|
| 722 |
|
| 723 |
+
df.drop(index_in_csv).to_csv(self.PENDING_FILE, index=False)
|
| 724 |
self.sync_pending_queue(direction="up")
|
| 725 |
|
| 726 |
audio_to_delete = row.get("Audio")
|
|
|
|
| 1001 |
# π’ NEW: Editable Textboxes for Admin Corrections
|
| 1002 |
gr.Markdown("#### βοΈ Edit Selected Entry Before Minting")
|
| 1003 |
with gr.Row():
|
| 1004 |
+
pending_timestamp = gr.Textbox(label="Timestamp ID", interactive=False)
|
| 1005 |
+
pending_orig_utt = gr.Textbox(visible=False)
|
| 1006 |
edit_utt = gr.Textbox(label="Utterance", interactive=True)
|
| 1007 |
edit_dialect = gr.Textbox(label="Dialect / Language", interactive=True)
|
| 1008 |
edit_clar = gr.Textbox(label="Clarification / Meaning", interactive=True)
|
|
|
|
| 1165 |
idx = evt.index[0]
|
| 1166 |
row = df.iloc[idx]
|
| 1167 |
audio_path = row.get("Audio")
|
| 1168 |
+
timestamp = str(row.get("Timestamp", ""))
|
| 1169 |
utt = str(row.get("Utterance", ""))
|
| 1170 |
clar = str(row.get("Clarification", ""))
|
| 1171 |
tone = str(row.get("Tone", ""))
|
| 1172 |
dialect = str(row.get("Dialect", ""))
|
| 1173 |
+
return audio_path, timestamp, utt, utt, dialect, clar, tone
|
| 1174 |
except:
|
| 1175 |
+
return None, "", "", "", "", "", ""
|
| 1176 |
|
| 1177 |
filter_dialect.change(self.get_pending_dataframe, inputs=[filter_dialect], outputs=[pending_df])
|
| 1178 |
btn_refresh.click(self.get_pending_dataframe, inputs=[filter_dialect], outputs=[pending_df])
|
| 1179 |
|
| 1180 |
# π’ FIX: Fill the textboxes when a row is clicked
|
| 1181 |
+
pending_df.select(select_pending_row, [pending_df], [pending_audio_player, pending_timestamp, pending_orig_utt, edit_utt, edit_dialect, edit_clar, edit_tone])
|
| 1182 |
|
| 1183 |
# π’ FIX: Pass the edited textboxes to the approval function, then auto-refresh the table
|
| 1184 |
+
btn_appr_p.click(self.admin_approve_pending, inputs=[pending_timestamp, pending_orig_utt, edit_utt, edit_dialect, edit_clar, edit_tone, pending_audio_player], outputs=[audit_log]).then(self.get_pending_dataframe, inputs=[filter_dialect], outputs=[pending_df])
|
| 1185 |
+
btn_rejt_p.click(self.admin_reject_pending, inputs=[pending_timestamp, pending_orig_utt], outputs=[audit_log]).then(self.get_pending_dataframe, inputs=[filter_dialect], outputs=[pending_df])
|
| 1186 |
btn_clear_pending.click(self.admin_clear_all_pending, outputs=[audit_log]).then(self.get_pending_dataframe, inputs=[filter_dialect], outputs=[pending_df])
|
| 1187 |
|
| 1188 |
def trigger_recovery():
|