toecm commited on
Commit
af64ed1
·
verified ·
1 Parent(s): e8c492e

Update src/ux_agent.py

Browse files
Files changed (1) hide show
  1. src/ux_agent.py +9 -53
src/ux_agent.py CHANGED
@@ -206,7 +206,8 @@ class AgentUX:
206
 
207
  # 🟢 BUG 1 & 2 FIX: Safely ignore empty triggers and return safe values
208
  if not audio_path:
209
- return empty_df, "Waiting for input...", self.get_quota_status(), "", None, "Neutral / Conversational", "", ""
 
210
 
211
  print("\n" + "="*40)
212
  print(f"🚀 PIPELINE TRIGGERED for {language_code}!")
@@ -221,7 +222,6 @@ class AgentUX:
221
  if hasattr(self.input, 'transcribe'):
222
  transcription_result = self.input.transcribe(audio_path, language=language_code)
223
  print(f"✅ Whisper Result: {transcription_result}")
224
- transcribed_text = transcription_result[0]['text']
225
 
226
  # Inside automated_pipeline:
227
  if isinstance(transcription_result, list) and len(transcription_result) > 0:
@@ -263,7 +263,7 @@ class AgentUX:
263
 
264
  df_data = [[
265
  safe_str(final_result.get("Source", "Unknown")),
266
- "source_tag",
267
  safe_str(transcribed_text),
268
  safe_str(final_result.get("dialect", "")),
269
  safe_str(final_result.get("clarification", "")),
@@ -637,16 +637,12 @@ class AgentUX:
637
  with gr.Tab("⛓️ PureChain History"):
638
  gr.Markdown("### 📜 Immutable Transaction Log & Audit Reports")
639
 
640
- # 🟢 Get unique origins for the dropdown
641
- unique_origins = self.trust.get_unique_origins()
642
- origin_choices = ["All Origins"] + unique_origins
643
-
644
  with gr.Row():
645
  start_date = gr.DateTime(label="Start Date", type="string")
646
  end_date = gr.DateTime(label="End Date", type="string")
647
- origin_filter = gr.Dropdown(choices=origin_choices, value="All Origins", label="Filter by IP Origin")
648
  btn_filter = gr.Button("🔍 Filter & Refresh", variant="primary")
649
 
 
650
  history_df = gr.Dataframe(
651
  headers=["Timestamp", "Utterance", "Dialect", "Data_Origin", "Block", "TX Hash"],
652
  interactive=False,
@@ -659,23 +655,17 @@ class AgentUX:
659
  explorer_link = gr.Markdown("Select a row to generate Explorer Link")
660
 
661
  # --- Internal Tab Functions ---
662
- def run_filter(s, e, origin):
663
  df = self.trust.get_filtered_history(s, e)
664
- if origin and origin != "All Origins":
665
- if "Data_Origin" in df.columns:
666
- df = df[df["Data_Origin"] == origin]
667
 
668
  display_cols = ["Timestamp", "Utterance", "Dialect", "Data_Origin", "Block", "TX Hash"]
669
  available = [c for c in display_cols if c in df.columns]
670
  return df[available]
671
 
672
- def generate_report(s, e, origin):
673
  df = self.trust.get_filtered_history(s, e)
674
- if origin and origin != "All Origins":
675
- if "Data_Origin" in df.columns:
676
- df = df[df["Data_Origin"] == origin]
677
-
678
  report_path = "/app/purechain_audit_report.csv"
 
679
  export_cols = ["Timestamp", "Utterance", "Dialect", "Clarification", "Data_Origin", "Block", "TX Hash"]
680
  available_cols = [c for c in export_cols if c in df.columns]
681
 
@@ -689,13 +679,9 @@ class AgentUX:
689
  except: return "Select a valid row"
690
 
691
  # --- Event Bindings ---
692
- btn_filter.click(run_filter, [start_date, end_date, origin_filter], [history_df])
693
 
694
- export_report_btn.click(
695
- generate_report,
696
- inputs=[start_date, end_date, origin_filter],
697
- outputs=[report_file]
698
- ).then(run_filter, [start_date, end_date, origin_filter], [history_df])
699
 
700
  history_df.select(make_explorer_link, [history_df], [explorer_link])
701
 
@@ -779,36 +765,6 @@ class AgentUX:
779
  btn_rejt_p.click(self.admin_reject_pending, inputs=[pending_idx], outputs=[audit_log])
780
  btn_clear_pending.click(self.admin_clear_all_pending, outputs=[audit_log])
781
 
782
- # History Tab
783
- def run_filter(s, e, origin): return self.trust.get_filtered_history(s, e)
784
- def generate_report(s, e):
785
- df = self.trust.get_filtered_history(s, e)
786
- # Ensure we are exporting the 'Data_Origin' or 'Source' column
787
- report_path = "/app/purechain_audit_report.csv"
788
-
789
- # 🟢 NEW: Add Origin Filtering
790
- if origin and origin != "All Origins":
791
- df = df[df["Data_Origin"] == origin]
792
-
793
- # Explicitly naming columns for your PhD folder structure
794
- display_cols = ["Timestamp", "Utterance", "Dialect", "Clarification", "Data_Origin", "Block", "TX Hash"]
795
- available_cols = [c for c in export_cols if c in df.columns]
796
-
797
- df[available_cols].to_csv(report_path, index=False, encoding='utf-8-sig')
798
- return report_path
799
-
800
- def make_explorer_link(evt: gr.SelectData, df):
801
- try:
802
- tx_hash = df.iloc[evt.index[0]]["TX Hash"]
803
- return f"🔍 **[View Transaction on Explorer](http://3.34.161.207:3000/tx/{tx_hash})**"
804
- except: return "Select a valid row"
805
-
806
- btn_filter.click(run_filter, [start_date, end_date, origin_filter], [history_df])
807
-
808
- export_report_btn.click(generate_report, inputs=[start_date, end_date], outputs=[report_file]).then(run_filter, [start_date, end_date], [history_df])
809
-
810
- history_df.select(make_explorer_link, [history_df], [explorer_link])
811
-
812
  # System Backup Bindings
813
  backup_btn.click(self.trust.create_system_backup, inputs=[backup_target, backup_desc], outputs=[backup_log])
814
  deploy_btn.click(self.trust.force_deploy_contract, inputs=[bytecode_input], outputs=[deployment_output])
 
206
 
207
  # 🟢 BUG 1 & 2 FIX: Safely ignore empty triggers and return safe values
208
  if not audio_path:
209
+ yield empty_df, "Waiting for input...", self.get_quota_status(), "", None, "Neutral / Conversational", "", ""
210
+ return
211
 
212
  print("\n" + "="*40)
213
  print(f"🚀 PIPELINE TRIGGERED for {language_code}!")
 
222
  if hasattr(self.input, 'transcribe'):
223
  transcription_result = self.input.transcribe(audio_path, language=language_code)
224
  print(f"✅ Whisper Result: {transcription_result}")
 
225
 
226
  # Inside automated_pipeline:
227
  if isinstance(transcription_result, list) and len(transcription_result) > 0:
 
263
 
264
  df_data = [[
265
  safe_str(final_result.get("Source", "Unknown")),
266
+ source_tag,
267
  safe_str(transcribed_text),
268
  safe_str(final_result.get("dialect", "")),
269
  safe_str(final_result.get("clarification", "")),
 
637
  with gr.Tab("⛓️ PureChain History"):
638
  gr.Markdown("### 📜 Immutable Transaction Log & Audit Reports")
639
 
 
 
 
 
640
  with gr.Row():
641
  start_date = gr.DateTime(label="Start Date", type="string")
642
  end_date = gr.DateTime(label="End Date", type="string")
 
643
  btn_filter = gr.Button("🔍 Filter & Refresh", variant="primary")
644
 
645
+ # 🟢 IP "Data_Origin" column is preserved here!
646
  history_df = gr.Dataframe(
647
  headers=["Timestamp", "Utterance", "Dialect", "Data_Origin", "Block", "TX Hash"],
648
  interactive=False,
 
655
  explorer_link = gr.Markdown("Select a row to generate Explorer Link")
656
 
657
  # --- Internal Tab Functions ---
658
+ def run_filter(s, e):
659
  df = self.trust.get_filtered_history(s, e)
 
 
 
660
 
661
  display_cols = ["Timestamp", "Utterance", "Dialect", "Data_Origin", "Block", "TX Hash"]
662
  available = [c for c in display_cols if c in df.columns]
663
  return df[available]
664
 
665
+ def generate_report(s, e):
666
  df = self.trust.get_filtered_history(s, e)
 
 
 
 
667
  report_path = "/app/purechain_audit_report.csv"
668
+
669
  export_cols = ["Timestamp", "Utterance", "Dialect", "Clarification", "Data_Origin", "Block", "TX Hash"]
670
  available_cols = [c for c in export_cols if c in df.columns]
671
 
 
679
  except: return "Select a valid row"
680
 
681
  # --- Event Bindings ---
682
+ btn_filter.click(run_filter, [start_date, end_date], [history_df])
683
 
684
+ export_report_btn.click(generate_report, inputs=[start_date, end_date], outputs=[report_file]).then(run_filter, [start_date, end_date], [history_df])
 
 
 
 
685
 
686
  history_df.select(make_explorer_link, [history_df], [explorer_link])
687
 
 
765
  btn_rejt_p.click(self.admin_reject_pending, inputs=[pending_idx], outputs=[audit_log])
766
  btn_clear_pending.click(self.admin_clear_all_pending, outputs=[audit_log])
767
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
768
  # System Backup Bindings
769
  backup_btn.click(self.trust.create_system_backup, inputs=[backup_target, backup_desc], outputs=[backup_log])
770
  deploy_btn.click(self.trust.force_deploy_contract, inputs=[bytecode_input], outputs=[deployment_output])