Leonydis137 commited on
Commit
0241455
·
verified ·
1 Parent(s): 037244c

Update exporter.py

Browse files
Files changed (1) hide show
  1. exporter.py +177 -0
exporter.py CHANGED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from memory_manager import embed_and_store, retrieve_relevant
3
+ from agent_engine import step_turn
4
+ from analysis_tools import analyze_sentiment_topics, plot_participation, generate_knowledge_graph
5
+ from exporter import export_txt, export_json, export_pdf, send_webhook
6
+
7
+ # Default agent parameters
8
+ DEFAULT_PARAMS = {
9
+ agent: {"creativity": 0.7, "criticality": 0.7}
10
+ for agent in ["Initiator", "Responder", "Guardian", "Provocateur", "Cultural", "Judge"]
11
+ }
12
+
13
+ # Agent color mapping
14
+ COLOR_MAP = {
15
+ "Initiator": "#e6f7ff",
16
+ "Responder": "#f6ffed",
17
+ "Guardian": "#fff7e6",
18
+ "Provocateur": "#f9e6ff",
19
+ "Cultural": "#e6ffed",
20
+ "Judge": "#f0f0f0",
21
+ "System": "#d9d9d9",
22
+ "User": "#ffffff"
23
+ }
24
+
25
+
26
+ def main():
27
+ with gr.Blocks(css="""
28
+ .convo-container {
29
+ max-height: 400px;
30
+ overflow-y: auto;
31
+ padding: 10px;
32
+ border: 1px solid #ccc;
33
+ border-radius: 8px;
34
+ background: #fafafa;
35
+ }
36
+ .message-card {
37
+ padding: 8px;
38
+ margin-bottom: 6px;
39
+ border-radius: 6px;
40
+ }
41
+ .agent-panel {
42
+ border: 1px solid #ddd;
43
+ padding: 6px;
44
+ border-radius: 4px;
45
+ margin: 4px;
46
+ }
47
+ """, title="Hexa-Agent Discussion System") as demo:
48
+ # States
49
+ conversation_state = gr.State([])
50
+ turn_state = gr.State(0)
51
+ topic_state = gr.State("")
52
+ params_state = gr.State(DEFAULT_PARAMS)
53
+
54
+ # Header
55
+ gr.Markdown("# 🧠 Modular Multi-Agent Discussion Platform")
56
+
57
+ # Controls
58
+ with gr.Row():
59
+ topic_input = gr.Textbox(label="Topic", placeholder="Enter topic...", value="Ethical AI")
60
+ set_topic_btn = gr.Button("Set Topic")
61
+ clear_btn = gr.Button("Clear Discussion")
62
+ with gr.Row():
63
+ step_btn = gr.Button("▶️ Next Turn")
64
+ gr.Markdown("---")
65
+
66
+ # Conversation display
67
+ convo_display = gr.HTML("<div class='convo-container' id='convo'></div>", label="Conversation")
68
+
69
+ # Agent Panels
70
+ with gr.Accordion("Agent Panels", open=False):
71
+ initiator_panel = gr.Textbox(label="Initiator Latest", interactive=False)
72
+ responder_panel = gr.Textbox(label="Responder Latest", interactive=False)
73
+ guardian_panel = gr.Textbox(label="Guardian Latest", interactive=False)
74
+ provocateur_panel = gr.Textbox(label="Provocateur Latest", interactive=False)
75
+ cultural_panel = gr.Textbox(label="Cultural Latest", interactive=False)
76
+ judge_panel = gr.Textbox(label="Judge Latest", interactive=False)
77
+
78
+ # Analysis Tab
79
+ with gr.Tab("Analysis"):
80
+ sentiment = gr.Textbox(label="Sentiment")
81
+ topics = gr.Textbox(label="Key Topics")
82
+ part_plot = gr.Image(label="Participation Chart")
83
+ graph_plot = gr.Image(label="Knowledge Graph")
84
+ analyze_btn = gr.Button("Run Analysis")
85
+ graph_btn = gr.Button("Generate Graph")
86
+
87
+ # Configuration Tab: Parameter Sliders
88
+ with gr.Tab("Configuration"):
89
+ sliders = {}
90
+ for agent in ["Initiator", "Responder", "Guardian", "Provocateur", "Cultural", "Judge"]:
91
+ with gr.Row():
92
+ sliders[f"{agent}_creativity"] = gr.Slider(0.0, 1.0, value=DEFAULT_PARAMS[agent]['creativity'], label=f"{agent} Creativity")
93
+ sliders[f"{agent}_criticality"] = gr.Slider(0.0, 1.0, value=DEFAULT_PARAMS[agent]['criticality'], label=f"{agent} Criticality")
94
+
95
+ # Export Tab
96
+ with gr.Tab("Export"):
97
+ fmt = gr.Radio(choices=["txt","json","pdf"], label="Format", value="txt")
98
+ export_btn = gr.Button("Export")
99
+ export_out = gr.File(label="Download")
100
+ webhook_url = gr.Textbox(label="Webhook URL")
101
+ send_btn = gr.Button("Send to Webhook")
102
+ send_status = gr.Textbox(label="Status")
103
+
104
+ # Event handlers
105
+ set_topic_btn.click(lambda t: ([], 0, t), inputs=[topic_input], outputs=[convo_display, turn_state, topic_state])
106
+ clear_btn.click(lambda: ([], 0, ""), outputs=[convo_display, turn_state, topic_state])
107
+
108
+ def on_step(convo, turn, topic, params, *slider_vals):
109
+ # Update params from sliders
110
+ agents = ["Initiator","Responder","Guardian","Provocateur","Cultural","Judge"]
111
+ new_params = {}
112
+ idx = 0
113
+ for agent in agents:
114
+ new_params[agent] = {
115
+ 'creativity': slider_vals[idx],
116
+ 'criticality': slider_vals[idx+1]
117
+ }
118
+ idx += 2
119
+ params = new_params
120
+ if turn == 0 and topic:
121
+ convo = [{"agent":"System","text":f"Topic: {topic}"}]
122
+ convo = step_turn(convo, turn, topic or topic_input.value, params)
123
+ # Build HTML
124
+ html = ''
125
+ for msg in convo:
126
+ color = COLOR_MAP.get(msg['agent'], '#ffffff')
127
+ html += f"<div class='message-card' style='background:{color};'><b>{msg['agent']}:</b> {msg['text']}</div>"
128
+ html += "<script>var c=document.getElementById('convo'); c.scrollTop=c.scrollHeight;</script>"
129
+ # Update panels
130
+ panels = []
131
+ for agent in agents:
132
+ panels.append(next((m['text'] for m in reversed(convo) if m['agent']==agent), ''))
133
+ return (html, convo, turn+1) + tuple(panels) + (params,)
134
+
135
+ # Connect step with sliders
136
+ step_btn.click(
137
+ on_step,
138
+ inputs=[conversation_state, turn_state, topic_state, params_state] + list(sliders.values()),
139
+ outputs=[convo_display, conversation_state, turn_state,
140
+ initiator_panel, responder_panel, guardian_panel,
141
+ provocateur_panel, cultural_panel, judge_panel,
142
+ params_state]
143
+ )
144
+
145
+ analyze_btn.click(
146
+ lambda convo: (
147
+ analyze_sentiment_topics(convo)['sentiment'],
148
+ ", ".join(analyze_sentiment_topics(convo)['topics']),
149
+ plot_participation(convo, 'participation.png')
150
+ ),
151
+ inputs=[conversation_state],
152
+ outputs=[sentiment, topics, part_plot]
153
+ )
154
+
155
+ graph_btn.click(
156
+ lambda convo: generate_knowledge_graph(convo, 'graph.png'),
157
+ inputs=[conversation_state],
158
+ outputs=[graph_plot]
159
+ )
160
+
161
+ export_btn.click(
162
+ lambda fmt, convo, topic, turn: {
163
+ 'txt': export_txt(convo, topic, turn),
164
+ 'json': export_json(convo, topic, turn),
165
+ 'pdf': export_pdf(convo, topic, turn)
166
+ }[fmt],
167
+ inputs=[fmt, conversation_state, topic_state, turn_state],
168
+ outputs=[export_out]
169
+ )
170
+
171
+ send_btn.click(send_webhook, inputs=[webhook_url, conversation_state, topic_state, turn_state], outputs=[send_status])
172
+
173
+ demo.launch()
174
+
175
+
176
+ if __name__ == '__main__':
177
+ main()