Leonydis137 commited on
Commit
bd7f92f
·
verified ·
1 Parent(s): 4ad3252

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -186
app.py CHANGED
@@ -600,6 +600,8 @@ def send_to_webhook(url):
600
  except Exception as e:
601
  return f"⚠️ Connection error: {str(e)}"
602
 
 
 
603
  # === GRADIO UI ===
604
  with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Discussion Platform") as demo:
605
  gr.Markdown("# 🧠 DeepSeek Hexa-Agent Discussion System")
@@ -624,6 +626,15 @@ with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Discussion Platform") as
624
  clear_btn = gr.Button("🔄 New Discussion", variant="stop")
625
  topic_btn = gr.Button("🎲 Random Topic", variant="secondary")
626
  ruling_btn = gr.Button("⚖️ Request Ruling", variant="primary")
 
 
 
 
 
 
 
 
 
627
 
628
  with gr.Tab("Agent Perspectives"):
629
  with gr.Row():
@@ -689,15 +700,16 @@ with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Discussion Platform") as
689
  with gr.Tab("Agent Configuration"):
690
  gr.Markdown("### Customize Agent Behavior")
691
  with gr.Row():
 
692
  for agent in ["Initiator", "Responder", "Guardian", "Provocateur", "Cultural", "Judge"]:
693
  with gr.Column():
694
  gr.Markdown(f"#### {agent}")
695
- agent_params[f"{agent}_creativity"] = gr.Slider(
696
- 0.0, 1.0, value=agent_params[agent]["creativity"],
697
  label="Creativity", interactive=True
698
  )
699
- agent_params[f"{agent}_critical"] = gr.Slider(
700
- 0.0, 1.0, value=agent_params[agent]["criticality"],
701
  label="Criticality", interactive=True
702
  )
703
 
@@ -730,7 +742,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Discussion Platform") as
730
  return (
731
  "<div class='convo-container'>New discussion started</div>",
732
  "", "", "", "", "", 0, "",
733
- {"agents": [], "counts": []}, "", None, ""
734
  )
735
 
736
  def new_topic():
@@ -738,6 +750,29 @@ with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Discussion Platform") as
738
  topic = generate_topic()
739
  return clear_result[:6] + (topic,) + clear_result[7:]
740
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
741
  def ask_judge(query):
742
  try:
743
  context = "\n".join([m['text'] for m in conversation[-3:]]) if conversation else "No context"
@@ -779,174 +814,34 @@ with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Discussion Platform") as
779
  return format_convo(), f"✅ Added: '{text[:30]}...'"
780
  return format_convo(), "Please enter text"
781
 
782
- def update_agent_params(*args):
783
- # Update global agent_params based on UI sliders
784
- params = agent_params.copy()
785
- for agent in params.keys():
786
- params[agent]["creativity"] = globals()[f"{agent}_creativity"].value
787
- params[agent]["criticality"] = globals()[f"{agent}_critical"].value
788
- return "Agent parameters updated!"
789
-
790
- # Connect UI components
791
- step_btn.click(
792
- step,
793
- inputs=[topic_display],
794
- outputs=[
795
- convo_display, intervention_display, outsider_display,
796
- cultural_display, judge_display, topic_display, turn_counter, agent_status
797
- ]
798
- )
799
-
800
- # === GRADIO UI ===
801
- with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Discussion Platform") as demo:
802
- gr.Markdown("# 🧠 DeepSeek Hexa-Agent Discussion System")
803
- gr.Markdown("### AI-Powered Complex Discourse Analysis")
804
-
805
- # Status panel
806
- with gr.Row():
807
- turn_counter = gr.Number(label="Turn Count", value=0, interactive=False)
808
- topic_display = gr.Textbox(label="Current Topic", interactive=False, lines=2)
809
- agent_status = gr.Textbox(label="Active Agents", value="💡 Initiator, 🔍 Responder", interactive=False)
810
-
811
- # Tabbed interface
812
- with gr.Tab("Live Discussion"):
813
- convo_display = gr.HTML(
814
- value="<div class='convo-container'>Discussion will appear here</div>",
815
- elem_id="convo-display"
816
- )
817
-
818
- with gr.Row():
819
- step_btn = gr.Button("▶️ Next Turn", variant="primary")
820
- auto_btn = gr.Button("🔴 Auto: OFF", variant="secondary")
821
- clear_btn = gr.Button("🔄 New Discussion", variant="stop")
822
- topic_btn = gr.Button("🎲 Random Topic", variant="secondary")
823
- ruling_btn = gr.Button("⚖️ Request Ruling", variant="primary")
824
-
825
- # ADDED: Guide the Discussion section in Live Discussion tab
826
- with gr.Accordion("💬 Guide the Discussion", open=False):
827
- topic_input = gr.Textbox(label="Set Custom Topic", placeholder="e.g., Ethics of AGI in cultural contexts...")
828
- with gr.Row():
829
- qbox = gr.Textbox(label="Ask the Depth Guardian", placeholder="What perspectives are missing?")
830
- ruling_qbox = gr.Textbox(label="Specific Question for Judge", placeholder="What should be our guiding principle?")
831
- with gr.Row():
832
- overseer_out = gr.Textbox(label="Depth Guardian Response", interactive=False)
833
- judge_out = gr.Textbox(label="Judge's Response", interactive=False)
834
-
835
- with gr.Tab("Agent Perspectives"):
836
- with gr.Row():
837
- with gr.Column(scale=1):
838
- gr.Markdown("### ⚖️ Depth Guardian")
839
- intervention_display = gr.Textbox(label="", interactive=False)
840
- with gr.Column(scale=1):
841
- gr.Markdown("### 🌐 Cross-Disciplinary")
842
- outsider_display = gr.Textbox(label="", interactive=False)
843
- with gr.Column(scale=1):
844
- gr.Markdown("### 🌍 Cultural Lens")
845
- cultural_display = gr.Textbox(label="", interactive=False)
846
-
847
- with gr.Row():
848
- with gr.Column(scale=3):
849
- gr.Markdown("### ⚖️ Final Judgment")
850
- judge_display = gr.Textbox(label="", interactive=False, lines=4)
851
-
852
- with gr.Tab("Analysis Dashboard"):
853
- gr.Markdown("### Conversation Insights")
854
- with gr.Row():
855
- sentiment_display = gr.Textbox(label="Discussion Sentiment", interactive=False)
856
- topics_display = gr.JSON(label="Key Topics")
857
-
858
- with gr.Row():
859
- agent_plot = gr.Plot(label="Agent Participation")
860
- analysis_btn = gr.Button("Generate Insights", variant="primary")
861
-
862
- with gr.Row():
863
- gr.Markdown("### Knowledge Graph")
864
- graph_btn = gr.Button("Generate Knowledge Graph", variant="secondary")
865
- graph_display = gr.Image(label="Concept Relationships", interactive=False)
866
-
867
- with gr.Tab("Collaboration"):
868
- gr.Markdown("### Real-Time Collaboration")
869
- with gr.Row():
870
- user_input = gr.Textbox(label="Your Contribution", placeholder="Add your perspective...")
871
- submit_btn = gr.Button("Add to Discussion")
872
-
873
- with gr.Row():
874
- voting_btn = gr.Button("👍 Vote for Current Direction")
875
- flag_btn = gr.Button("🚩 Flag Issue")
876
-
877
- with gr.Row():
878
- user_feedback = gr.Textbox(label="Community Feedback", interactive=False)
879
-
880
- with gr.Tab("Export & Integrate"):
881
- with gr.Row():
882
- format_radio = gr.Radio(
883
- ["PDF Report", "JSON Data", "Text Transcript"],
884
- label="Export Format",
885
- value="PDF Report"
886
- )
887
- export_btn = gr.Button("Export Discussion", variant="primary")
888
- export_result = gr.File(label="Download File")
889
-
890
- with gr.Row():
891
- gr.Markdown("### API Integration")
892
- webhook_url = gr.Textbox(label="Webhook URL", placeholder="https://your-platform.com/webhook")
893
- integrate_btn = gr.Button("Connect to External Platform", variant="secondary")
894
- integration_status = gr.Textbox(label="Status", interactive=False)
895
-
896
- with gr.Tab("Agent Configuration"):
897
- gr.Markdown("### Customize Agent Behavior")
898
- with gr.Row():
899
- agent_sliders = {}
900
- for agent in ["Initiator", "Responder", "Guardian", "Provocateur", "Cultural", "Judge"]:
901
- with gr.Column():
902
- gr.Markdown(f"#### {agent}")
903
- agent_sliders[f"{agent}_creativity"] = gr.Slider(
904
- 0.0, 1.0, value=0.7,
905
- label="Creativity", interactive=True
906
- )
907
- agent_sliders[f"{agent}_critical"] = gr.Slider(
908
- 0.0, 1.0, value=0.5,
909
- label="Criticality", interactive=True
910
- )
911
-
912
- # Custom CSS
913
- demo.css = """
914
- .convo-container {
915
- max-height: 400px;
916
- overflow-y: auto;
917
- padding: 15px;
918
- border: 1px solid #e0e0e0;
919
- border-radius: 8px;
920
- background-color: #f9f9f9;
921
- line-height: 1.6;
922
- }
923
- .convo-container p {
924
- margin-bottom: 10px;
925
- }
926
- #topic-display {
927
- font-weight: bold;
928
- font-size: 1.1em;
929
- }
930
- """
931
 
932
- # Event handlers
933
- def clear_convo():
934
- global conversation, turn_count, current_topic
935
- conversation = []
936
- turn_count = 0
937
- current_topic = ""
938
- return (
939
- "<div class='convo-container'>New discussion started</div>",
940
- "", "", "", "", "", 0, "",
941
- {"agents": [], "counts": []}, "", None, "", ""
942
- )
943
 
944
- def new_topic():
945
- clear_result = clear_convo()
946
- topic = generate_topic()
947
- return clear_result[:6] + (topic,) + clear_result[7:]
 
 
 
 
 
 
 
 
 
948
 
949
- # Connect qbox and ruling_qbox submit handlers
950
  qbox.submit(
951
  overseer_respond,
952
  inputs=qbox,
@@ -959,7 +854,6 @@ with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Discussion Platform") as
959
  outputs=judge_out
960
  )
961
 
962
- # Connect other UI components
963
  step_btn.click(
964
  step,
965
  inputs=[topic_input],
@@ -1031,21 +925,6 @@ with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Discussion Platform") as
1031
  outputs=[user_feedback]
1032
  )
1033
 
1034
- # Connect agent parameter sliders
1035
- def update_agent_params(init_creat, init_crit, resp_creat, resp_crit,
1036
- guard_creat, guard_crit, prov_creat, prov_crit,
1037
- cult_creat, cult_crit, judge_creat, judge_crit):
1038
- global agent_params
1039
- agent_params = {
1040
- "Initiator": {"creativity": init_creat, "criticality": init_crit},
1041
- "Responder": {"creativity": resp_creat, "criticality": resp_crit},
1042
- "Guardian": {"creativity": guard_creat, "criticality": guard_crit},
1043
- "Provocateur": {"creativity": prov_creat, "criticality": prov_crit},
1044
- "Cultural": {"creativity": cult_creat, "criticality": cult_crit},
1045
- "Judge": {"creativity": judge_creat, "criticality": judge_crit}
1046
- }
1047
- return "✅ Agent parameters updated!"
1048
-
1049
  # Create input list for slider change events
1050
  slider_inputs = [agent_sliders[f"{agent}_{param}"]
1051
  for agent in ["Initiator", "Responder", "Guardian", "Provocateur", "Cultural", "Judge"]
 
600
  except Exception as e:
601
  return f"⚠️ Connection error: {str(e)}"
602
 
603
+ # ... [Keep all the imports, config, and function definitions above] ...
604
+
605
  # === GRADIO UI ===
606
  with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Discussion Platform") as demo:
607
  gr.Markdown("# 🧠 DeepSeek Hexa-Agent Discussion System")
 
626
  clear_btn = gr.Button("🔄 New Discussion", variant="stop")
627
  topic_btn = gr.Button("🎲 Random Topic", variant="secondary")
628
  ruling_btn = gr.Button("⚖️ Request Ruling", variant="primary")
629
+
630
+ with gr.Accordion("💬 Guide the Discussion", open=False):
631
+ topic_input = gr.Textbox(label="Set Custom Topic", placeholder="e.g., Ethics of AGI in cultural contexts...")
632
+ with gr.Row():
633
+ qbox = gr.Textbox(label="Ask the Depth Guardian", placeholder="What perspectives are missing?")
634
+ ruling_qbox = gr.Textbox(label="Specific Question for Judge", placeholder="What should be our guiding principle?")
635
+ with gr.Row():
636
+ overseer_out = gr.Textbox(label="Depth Guardian Response", interactive=False)
637
+ judge_out = gr.Textbox(label="Judge's Response", interactive=False)
638
 
639
  with gr.Tab("Agent Perspectives"):
640
  with gr.Row():
 
700
  with gr.Tab("Agent Configuration"):
701
  gr.Markdown("### Customize Agent Behavior")
702
  with gr.Row():
703
+ agent_sliders = {}
704
  for agent in ["Initiator", "Responder", "Guardian", "Provocateur", "Cultural", "Judge"]:
705
  with gr.Column():
706
  gr.Markdown(f"#### {agent}")
707
+ agent_sliders[f"{agent}_creativity"] = gr.Slider(
708
+ 0.0, 1.0, value=0.7,
709
  label="Creativity", interactive=True
710
  )
711
+ agent_sliders[f"{agent}_critical"] = gr.Slider(
712
+ 0.0, 1.0, value=0.5,
713
  label="Criticality", interactive=True
714
  )
715
 
 
742
  return (
743
  "<div class='convo-container'>New discussion started</div>",
744
  "", "", "", "", "", 0, "",
745
+ {"agents": [], "counts": []}, "", None, "", ""
746
  )
747
 
748
  def new_topic():
 
750
  topic = generate_topic()
751
  return clear_result[:6] + (topic,) + clear_result[7:]
752
 
753
+ # === OVERSEER QUERY HANDLER ===
754
+ def overseer_respond(query):
755
+ try:
756
+ context = "\n".join([m['text'] for m in conversation[-3:]]) if conversation else "No context"
757
+ messages = [{"role": "user", "content": f"Discussion Topic: {current_topic}\n\nRecent context:\n{context}\n\nQuery: {query}"}]
758
+ return safe_chat_completion(
759
+ OVERSEER_PROMPT,
760
+ messages,
761
+ temperature=0.5 + agent_params["Guardian"]["criticality"] * 0.4
762
+ )
763
+ except Exception as e:
764
+ return f"[Overseer Error: {str(e)}]"
765
+
766
+ # === JUDGE RULING HANDLER ===
767
+ def request_ruling():
768
+ try:
769
+ ruling = judge_ruling()
770
+ conversation.append({"agent": "⚖️ Judge", "text": ruling})
771
+ embed_and_store(ruling, "Judge")
772
+ return ruling
773
+ except Exception as e:
774
+ return f"[Judge Error: {str(e)}]"
775
+
776
  def ask_judge(query):
777
  try:
778
  context = "\n".join([m['text'] for m in conversation[-3:]]) if conversation else "No context"
 
814
  return format_convo(), f"✅ Added: '{text[:30]}...'"
815
  return format_convo(), "Please enter text"
816
 
817
+ def toggle_auto():
818
+ global auto_mode
819
+ auto_mode = not auto_mode
820
+ if auto_mode:
821
+ threading.Thread(target=auto_loop, daemon=True).start()
822
+ return "🔴 Auto: OFF" if not auto_mode else "🟢 Auto: ON"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
823
 
824
+ def auto_loop():
825
+ global auto_mode
826
+ while auto_mode:
827
+ step()
828
+ time.sleep(6)
 
 
 
 
 
 
829
 
830
+ def update_agent_params(init_creat, init_crit, resp_creat, resp_crit,
831
+ guard_creat, guard_crit, prov_creat, prov_crit,
832
+ cult_creat, cult_crit, judge_creat, judge_crit):
833
+ global agent_params
834
+ agent_params = {
835
+ "Initiator": {"creativity": init_creat, "criticality": init_crit},
836
+ "Responder": {"creativity": resp_creat, "criticality": resp_crit},
837
+ "Guardian": {"creativity": guard_creat, "criticality": guard_crit},
838
+ "Provocateur": {"creativity": prov_creat, "criticality": prov_crit},
839
+ "Cultural": {"creativity": cult_creat, "criticality": cult_crit},
840
+ "Judge": {"creativity": judge_creat, "criticality": judge_crit}
841
+ }
842
+ return "✅ Agent parameters updated!"
843
 
844
+ # Connect UI components
845
  qbox.submit(
846
  overseer_respond,
847
  inputs=qbox,
 
854
  outputs=judge_out
855
  )
856
 
 
857
  step_btn.click(
858
  step,
859
  inputs=[topic_input],
 
925
  outputs=[user_feedback]
926
  )
927
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
928
  # Create input list for slider change events
929
  slider_inputs = [agent_sliders[f"{agent}_{param}"]
930
  for agent in ["Initiator", "Responder", "Guardian", "Provocateur", "Cultural", "Judge"]