Leonydis137 commited on
Commit
9106848
Β·
verified Β·
1 Parent(s): ef3e7dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +219 -12
app.py CHANGED
@@ -796,59 +796,266 @@ with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Discussion Platform") as
796
  cultural_display, judge_display, topic_display, turn_counter, agent_status
797
  ]
798
  )
799
- qbox.submit(ask_judge, inputs=gr.Textbox(), outputs=gr.Textbox())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
800
  auto_btn.click(
801
- lambda: ("🟒 Auto: ON" if not auto_mode else "πŸ”΄ Auto: OFF"),
802
  outputs=auto_btn
803
  )
 
804
  clear_btn.click(
805
  clear_convo,
806
  outputs=[
807
  convo_display, intervention_display, outsider_display,
808
  cultural_display, judge_display, topic_display, turn_counter,
809
- agent_status, agent_plot, graph_display
810
  ]
811
  )
 
812
  topic_btn.click(
813
  new_topic,
814
  outputs=[convo_display, topic_display, turn_counter]
815
  )
 
816
  ruling_btn.click(
817
- lambda: judge_ruling(),
818
  outputs=[judge_display]
819
  )
 
820
  analysis_btn.click(
821
  run_analysis,
822
- outputs=[sentiment_display, topics_display, agent_plot, topics_display]
823
  )
 
824
  graph_btn.click(
825
  generate_knowledge_graph,
826
  outputs=[graph_display]
827
  )
 
828
  export_btn.click(
829
  export_handler,
830
  inputs=[format_radio],
831
  outputs=[export_result]
832
  )
 
833
  integrate_btn.click(
834
  send_to_webhook,
835
  inputs=[webhook_url],
836
  outputs=[integration_status]
837
  )
 
838
  submit_btn.click(
839
  add_user_contribution,
840
  inputs=[user_input],
841
  outputs=[convo_display, user_feedback]
842
  )
843
 
844
- # Connect all agent parameter sliders
845
- param_components = [globals()[f"{agent}_{param}"]
846
- for agent in agent_params.keys()
847
- for param in ["creativity", "critical"]]
848
- for comp in param_components:
849
- comp.change(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
850
  update_agent_params,
851
- inputs=param_components,
852
  outputs=[gr.Textbox(visible=False)]
853
  )
854
 
 
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
+ # ADDED: Proper event handler connections
950
+ # Connect qbox and ruling_qbox submit handlers
951
+ qbox.submit(
952
+ overseer_respond,
953
+ inputs=qbox,
954
+ outputs=overseer_out
955
+ )
956
+
957
+ ruling_qbox.submit(
958
+ ask_judge,
959
+ inputs=ruling_qbox,
960
+ outputs=judge_out
961
+ )
962
+
963
+ # Connect other UI components
964
+ step_btn.click(
965
+ step,
966
+ inputs=[topic_input],
967
+ outputs=[
968
+ convo_display, intervention_display, outsider_display,
969
+ cultural_display, judge_display, topic_display, turn_counter, agent_status
970
+ ]
971
+ )
972
+
973
  auto_btn.click(
974
+ toggle_auto,
975
  outputs=auto_btn
976
  )
977
+
978
  clear_btn.click(
979
  clear_convo,
980
  outputs=[
981
  convo_display, intervention_display, outsider_display,
982
  cultural_display, judge_display, topic_display, turn_counter,
983
+ agent_status, agent_plot, graph_display, user_feedback
984
  ]
985
  )
986
+
987
  topic_btn.click(
988
  new_topic,
989
  outputs=[convo_display, topic_display, turn_counter]
990
  )
991
+
992
  ruling_btn.click(
993
+ request_ruling,
994
  outputs=[judge_display]
995
  )
996
+
997
  analysis_btn.click(
998
  run_analysis,
999
+ outputs=[sentiment_display, topics_display, agent_plot]
1000
  )
1001
+
1002
  graph_btn.click(
1003
  generate_knowledge_graph,
1004
  outputs=[graph_display]
1005
  )
1006
+
1007
  export_btn.click(
1008
  export_handler,
1009
  inputs=[format_radio],
1010
  outputs=[export_result]
1011
  )
1012
+
1013
  integrate_btn.click(
1014
  send_to_webhook,
1015
  inputs=[webhook_url],
1016
  outputs=[integration_status]
1017
  )
1018
+
1019
  submit_btn.click(
1020
  add_user_contribution,
1021
  inputs=[user_input],
1022
  outputs=[convo_display, user_feedback]
1023
  )
1024
 
1025
+ voting_btn.click(
1026
+ lambda: "βœ… Your vote has been recorded!",
1027
+ outputs=[user_feedback]
1028
+ )
1029
+
1030
+ flag_btn.click(
1031
+ lambda: "🚩 Issue flagged for moderator review",
1032
+ outputs=[user_feedback]
1033
+ )
1034
+
1035
+ # Connect agent parameter sliders
1036
+ def update_agent_params(init_creat, init_crit, resp_creat, resp_crit,
1037
+ guard_creat, guard_crit, prov_creat, prov_crit,
1038
+ cult_creat, cult_crit, judge_creat, judge_crit):
1039
+ global agent_params
1040
+ agent_params = {
1041
+ "Initiator": {"creativity": init_creat, "criticality": init_crit},
1042
+ "Responder": {"creativity": resp_creat, "criticality": resp_crit},
1043
+ "Guardian": {"creativity": guard_creat, "criticality": guard_crit},
1044
+ "Provocateur": {"creativity": prov_creat, "criticality": prov_crit},
1045
+ "Cultural": {"creativity": cult_creat, "criticality": cult_crit},
1046
+ "Judge": {"creativity": judge_creat, "criticality": judge_crit}
1047
+ }
1048
+ return "βœ… Agent parameters updated!"
1049
+
1050
+ # Create input list for slider change events
1051
+ slider_inputs = [agent_sliders[f"{agent}_{param}"]
1052
+ for agent in ["Initiator", "Responder", "Guardian", "Provocateur", "Cultural", "Judge"]
1053
+ for param in ["creativity", "critical"]]
1054
+
1055
+ for slider in slider_inputs:
1056
+ slider.change(
1057
  update_agent_params,
1058
+ inputs=slider_inputs,
1059
  outputs=[gr.Textbox(visible=False)]
1060
  )
1061