Spaces:
Running
Running
GitHub Actions commited on
Commit ยท
52ece7a
1
Parent(s): 5a85ed7
๐ Automated sync from GitHub
Browse files- src/ux_agent.py +22 -13
src/ux_agent.py
CHANGED
|
@@ -575,12 +575,14 @@ class AgentUX:
|
|
| 575 |
|
| 576 |
return pd.DataFrame(columns=["Timestamp", "Operator_ID", "Feedback_Text", "Image_Reference"])
|
| 577 |
|
| 578 |
-
def get_pending_dataframe(self):
|
| 579 |
if os.path.exists(self.PENDING_FILE):
|
| 580 |
df = pd.read_csv(self.PENDING_FILE)
|
| 581 |
cols = ["User", "Data_Origin", "Utterance", "Dialect", "Clarification", "Clarification_Source", "Tone", "Audio", "Timestamp"]
|
| 582 |
for c in cols:
|
| 583 |
if c not in df.columns: df[c] = ""
|
|
|
|
|
|
|
| 584 |
return df[cols]
|
| 585 |
return pd.DataFrame(columns=["User", "Data_Origin", "Utterance", "Dialect", "Clarification", "Clarification_Source", "Tone", "Audio", "Timestamp"])
|
| 586 |
|
|
@@ -655,25 +657,28 @@ class AgentUX:
|
|
| 655 |
self.last_pending_count = count
|
| 656 |
return f"### {label} - Review Submissions from React Games", sound
|
| 657 |
|
| 658 |
-
def admin_approve_pending(self, index, edited_utt, edited_clar, edited_tone):
|
| 659 |
try:
|
| 660 |
df = pd.read_csv(self.PENDING_FILE)
|
| 661 |
row = df.iloc[int(index)]
|
| 662 |
|
| 663 |
# ๐ข Use the edited text instead of the original row data
|
| 664 |
final_utt = edited_utt if edited_utt else row["Utterance"]
|
|
|
|
| 665 |
final_clar = edited_clar if edited_clar else row["Clarification"]
|
| 666 |
final_tone = edited_tone if edited_tone else row["Tone"]
|
| 667 |
|
|
|
|
|
|
|
| 668 |
self.trust.update_dataset_csv(
|
| 669 |
-
|
| 670 |
-
row.get("Context", ""), "",
|
| 671 |
row.get("Data_Origin", ""), "Admin Edit", row.get("User", "")
|
| 672 |
)
|
| 673 |
|
| 674 |
payload = {
|
| 675 |
"original": final_utt,
|
| 676 |
-
"dialect":
|
| 677 |
"clarification": final_clar,
|
| 678 |
"tone": final_tone,
|
| 679 |
"user": str(row.get("User", ""))
|
|
@@ -975,11 +980,12 @@ class AgentUX:
|
|
| 975 |
pending_header = gr.Markdown("### ๐ฎ Pending (0) - Review Submissions from React Games")
|
| 976 |
with gr.Row():
|
| 977 |
with gr.Column(scale=3):
|
|
|
|
| 978 |
pending_df = gr.Dataframe(headers=["User", "Data_Origin", "Utterance", "Dialect", "Clarification", "Tone", "Audio", "Timestamp"], interactive=False, wrap=False, row_count=(1, "dynamic"))
|
| 979 |
with gr.Column(scale=1):
|
| 980 |
gr.Markdown("#### ๐ง Audio Auditor")
|
| 981 |
btn_refresh = gr.Button("๐ Refresh List")
|
| 982 |
-
pending_audio_player = gr.Audio(label="
|
| 983 |
audit_log = gr.Textbox(label="Audit Status", interactive=False)
|
| 984 |
|
| 985 |
# ๐ข NEW: Editable Textboxes for Admin Corrections
|
|
@@ -987,6 +993,7 @@ class AgentUX:
|
|
| 987 |
with gr.Row():
|
| 988 |
pending_idx = gr.Number(label="Row Index", precision=0, interactive=False)
|
| 989 |
edit_utt = gr.Textbox(label="Utterance", interactive=True)
|
|
|
|
| 990 |
edit_clar = gr.Textbox(label="Clarification / Meaning", interactive=True)
|
| 991 |
edit_tone = gr.Textbox(label="Tone", interactive=True)
|
| 992 |
|
|
@@ -1150,19 +1157,21 @@ class AgentUX:
|
|
| 1150 |
utt = str(row.get("Utterance", ""))
|
| 1151 |
clar = str(row.get("Clarification", ""))
|
| 1152 |
tone = str(row.get("Tone", ""))
|
| 1153 |
-
|
|
|
|
| 1154 |
except:
|
| 1155 |
-
return None, 0, "", "", ""
|
| 1156 |
|
| 1157 |
-
|
|
|
|
| 1158 |
|
| 1159 |
# ๐ข FIX: Fill the textboxes when a row is clicked
|
| 1160 |
-
pending_df.select(select_pending_row, [pending_df], [pending_audio_player, pending_idx, edit_utt, edit_clar, edit_tone])
|
| 1161 |
|
| 1162 |
# ๐ข FIX: Pass the edited textboxes to the approval function, then auto-refresh the table
|
| 1163 |
-
btn_appr_p.click(self.admin_approve_pending, inputs=[pending_idx, edit_utt, edit_clar, edit_tone], outputs=[audit_log]).then(self.get_pending_dataframe, outputs=[pending_df])
|
| 1164 |
-
btn_rejt_p.click(self.admin_reject_pending, inputs=[pending_idx], outputs=[audit_log]).then(self.get_pending_dataframe, outputs=[pending_df])
|
| 1165 |
-
btn_clear_pending.click(self.admin_clear_all_pending, outputs=[audit_log]).then(self.get_pending_dataframe, outputs=[pending_df])
|
| 1166 |
|
| 1167 |
def trigger_recovery():
|
| 1168 |
try:
|
|
|
|
| 575 |
|
| 576 |
return pd.DataFrame(columns=["Timestamp", "Operator_ID", "Feedback_Text", "Image_Reference"])
|
| 577 |
|
| 578 |
+
def get_pending_dataframe(self, dialect_filter="All"):
|
| 579 |
if os.path.exists(self.PENDING_FILE):
|
| 580 |
df = pd.read_csv(self.PENDING_FILE)
|
| 581 |
cols = ["User", "Data_Origin", "Utterance", "Dialect", "Clarification", "Clarification_Source", "Tone", "Audio", "Timestamp"]
|
| 582 |
for c in cols:
|
| 583 |
if c not in df.columns: df[c] = ""
|
| 584 |
+
if dialect_filter and dialect_filter != "All":
|
| 585 |
+
df = df[df["Dialect"] == dialect_filter]
|
| 586 |
return df[cols]
|
| 587 |
return pd.DataFrame(columns=["User", "Data_Origin", "Utterance", "Dialect", "Clarification", "Clarification_Source", "Tone", "Audio", "Timestamp"])
|
| 588 |
|
|
|
|
| 657 |
self.last_pending_count = count
|
| 658 |
return f"### {label} - Review Submissions from React Games", sound
|
| 659 |
|
| 660 |
+
def admin_approve_pending(self, index, edited_utt, edited_dialect, edited_clar, edited_tone, trimmed_audio_path):
|
| 661 |
try:
|
| 662 |
df = pd.read_csv(self.PENDING_FILE)
|
| 663 |
row = df.iloc[int(index)]
|
| 664 |
|
| 665 |
# ๐ข Use the edited text instead of the original row data
|
| 666 |
final_utt = edited_utt if edited_utt else row["Utterance"]
|
| 667 |
+
final_dialect = edited_dialect if edited_dialect else row["Dialect"]
|
| 668 |
final_clar = edited_clar if edited_clar else row["Clarification"]
|
| 669 |
final_tone = edited_tone if edited_tone else row["Tone"]
|
| 670 |
|
| 671 |
+
final_audio = trimmed_audio_path if trimmed_audio_path and os.path.exists(trimmed_audio_path) else row["Audio"]
|
| 672 |
+
|
| 673 |
self.trust.update_dataset_csv(
|
| 674 |
+
final_dialect, final_utt, final_clar, final_tone,
|
| 675 |
+
row.get("Context", ""), "", final_audio, row.get("Pragmatic_Analysis", ""),
|
| 676 |
row.get("Data_Origin", ""), "Admin Edit", row.get("User", "")
|
| 677 |
)
|
| 678 |
|
| 679 |
payload = {
|
| 680 |
"original": final_utt,
|
| 681 |
+
"dialect": final_dialect,
|
| 682 |
"clarification": final_clar,
|
| 683 |
"tone": final_tone,
|
| 684 |
"user": str(row.get("User", ""))
|
|
|
|
| 980 |
pending_header = gr.Markdown("### ๐ฎ Pending (0) - Review Submissions from React Games")
|
| 981 |
with gr.Row():
|
| 982 |
with gr.Column(scale=3):
|
| 983 |
+
filter_dialect = gr.Dropdown(choices=["All"] + dropdown_choices, value="All", label="Filter by Dialect")
|
| 984 |
pending_df = gr.Dataframe(headers=["User", "Data_Origin", "Utterance", "Dialect", "Clarification", "Tone", "Audio", "Timestamp"], interactive=False, wrap=False, row_count=(1, "dynamic"))
|
| 985 |
with gr.Column(scale=1):
|
| 986 |
gr.Markdown("#### ๐ง Audio Auditor")
|
| 987 |
btn_refresh = gr.Button("๐ Refresh List")
|
| 988 |
+
pending_audio_player = gr.Audio(label="Trim or Preview Audio", type="filepath", interactive=True)
|
| 989 |
audit_log = gr.Textbox(label="Audit Status", interactive=False)
|
| 990 |
|
| 991 |
# ๐ข NEW: Editable Textboxes for Admin Corrections
|
|
|
|
| 993 |
with gr.Row():
|
| 994 |
pending_idx = gr.Number(label="Row Index", precision=0, interactive=False)
|
| 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)
|
| 998 |
edit_tone = gr.Textbox(label="Tone", interactive=True)
|
| 999 |
|
|
|
|
| 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, idx, utt, dialect, clar, tone
|
| 1162 |
except:
|
| 1163 |
+
return None, 0, "", "", "", ""
|
| 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, pending_idx, edit_utt, edit_dialect, edit_clar, edit_tone])
|
| 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=[pending_idx, 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])
|
| 1173 |
+
btn_rejt_p.click(self.admin_reject_pending, inputs=[pending_idx], outputs=[audit_log]).then(self.get_pending_dataframe, inputs=[filter_dialect], outputs=[pending_df])
|
| 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():
|
| 1177 |
try:
|