Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -194,11 +194,21 @@ def retrieve_relevant_memory(query, k=3):
|
|
194 |
# - safe_chat_completion (already replaced above)
|
195 |
# - get_embedding (already replaced above)
|
196 |
|
|
|
|
|
197 |
# === GRADIO UI ===
|
198 |
with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Discussion Platform") as demo:
|
199 |
gr.Markdown("# π§ Hexa-Agent Discussion System (Free Version)")
|
200 |
gr.Markdown("### Powered by Open-Source Models")
|
201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
# Status panel
|
203 |
with gr.Row():
|
204 |
turn_counter = gr.Number(label="Turn Count", value=0, interactive=False)
|
@@ -228,83 +238,8 @@ with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Discussion Platform") as
|
|
228 |
overseer_out = gr.Textbox(label="Depth Guardian Response", interactive=False)
|
229 |
judge_out = gr.Textbox(label="Judge's Response", interactive=False)
|
230 |
|
231 |
-
|
232 |
-
|
233 |
-
with gr.Column(scale=1):
|
234 |
-
gr.Markdown("### βοΈ Depth Guardian")
|
235 |
-
intervention_display = gr.Textbox(label="", interactive=False)
|
236 |
-
with gr.Column(scale=1):
|
237 |
-
gr.Markdown("### π Cross-Disciplinary")
|
238 |
-
outsider_display = gr.Textbox(label="", interactive=False)
|
239 |
-
with gr.Column(scale=1):
|
240 |
-
gr.Markdown("### π Cultural Lens")
|
241 |
-
cultural_display = gr.Textbox(label="", interactive=False)
|
242 |
-
|
243 |
-
with gr.Row():
|
244 |
-
with gr.Column(scale=3):
|
245 |
-
gr.Markdown("### βοΈ Final Judgment")
|
246 |
-
judge_display = gr.Textbox(label="", interactive=False, lines=4)
|
247 |
-
|
248 |
-
with gr.Tab("Analysis Dashboard"):
|
249 |
-
gr.Markdown("### Conversation Insights")
|
250 |
-
with gr.Row():
|
251 |
-
sentiment_display = gr.Textbox(label="Discussion Sentiment", interactive=False)
|
252 |
-
topics_display = gr.JSON(label="Key Topics")
|
253 |
-
|
254 |
-
with gr.Row():
|
255 |
-
agent_plot = gr.Plot(label="Agent Participation")
|
256 |
-
analysis_btn = gr.Button("Generate Insights", variant="primary")
|
257 |
-
|
258 |
-
with gr.Row():
|
259 |
-
gr.Markdown("### Knowledge Graph")
|
260 |
-
graph_btn = gr.Button("Generate Knowledge Graph", variant="secondary")
|
261 |
-
graph_display = gr.Image(label="Concept Relationships", interactive=False)
|
262 |
-
|
263 |
-
with gr.Tab("Collaboration"):
|
264 |
-
gr.Markdown("### Real-Time Collaboration")
|
265 |
-
with gr.Row():
|
266 |
-
user_input = gr.Textbox(label="Your Contribution", placeholder="Add your perspective...")
|
267 |
-
submit_btn = gr.Button("Add to Discussion")
|
268 |
-
|
269 |
-
with gr.Row():
|
270 |
-
voting_btn = gr.Button("π Vote for Current Direction")
|
271 |
-
flag_btn = gr.Button("π© Flag Issue")
|
272 |
-
|
273 |
-
with gr.Row():
|
274 |
-
user_feedback = gr.Textbox(label="Community Feedback", interactive=False)
|
275 |
-
|
276 |
-
with gr.Tab("Export & Integrate"):
|
277 |
-
with gr.Row():
|
278 |
-
format_radio = gr.Radio(
|
279 |
-
["PDF Report", "JSON Data", "Text Transcript"],
|
280 |
-
label="Export Format",
|
281 |
-
value="PDF Report"
|
282 |
-
)
|
283 |
-
export_btn = gr.Button("Export Discussion", variant="primary")
|
284 |
-
export_result = gr.File(label="Download File")
|
285 |
-
|
286 |
-
with gr.Row():
|
287 |
-
gr.Markdown("### API Integration")
|
288 |
-
webhook_url = gr.Textbox(label="Webhook URL", placeholder="https://your-platform.com/webhook")
|
289 |
-
integrate_btn = gr.Button("Connect to External Platform", variant="secondary")
|
290 |
-
integration_status = gr.Textbox(label="Status", interactive=False)
|
291 |
-
|
292 |
-
with gr.Tab("Agent Configuration"):
|
293 |
-
gr.Markdown("### Customize Agent Behavior")
|
294 |
-
with gr.Row():
|
295 |
-
agent_sliders = {}
|
296 |
-
for agent in ["Initiator", "Responder", "Guardian", "Provocateur", "Cultural", "Judge"]:
|
297 |
-
with gr.Column():
|
298 |
-
gr.Markdown(f"#### {agent}")
|
299 |
-
agent_sliders[f"{agent}_creativity"] = gr.Slider(
|
300 |
-
0.0, 1.0, value=0.7,
|
301 |
-
label="Creativity", interactive=True
|
302 |
-
)
|
303 |
-
agent_sliders[f"{agent}_critical"] = gr.Slider(
|
304 |
-
0.0, 1.0, value=0.5,
|
305 |
-
label="Criticality", interactive=True
|
306 |
-
)
|
307 |
-
|
308 |
# Custom CSS
|
309 |
demo.css = """
|
310 |
.convo-container {
|
@@ -341,7 +276,111 @@ with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Discussion Platform") as
|
|
341 |
</div>
|
342 |
""")
|
343 |
|
344 |
-
#
|
345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
|
347 |
demo.launch()
|
|
|
194 |
# - safe_chat_completion (already replaced above)
|
195 |
# - get_embedding (already replaced above)
|
196 |
|
197 |
+
# ... [Keep all imports, config, and function definitions above] ...
|
198 |
+
|
199 |
# === GRADIO UI ===
|
200 |
with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Discussion Platform") as demo:
|
201 |
gr.Markdown("# π§ Hexa-Agent Discussion System (Free Version)")
|
202 |
gr.Markdown("### Powered by Open-Source Models")
|
203 |
|
204 |
+
# State variables
|
205 |
+
conversation_state = gr.State([])
|
206 |
+
turn_count_state = gr.State(0)
|
207 |
+
current_topic_state = gr.State("")
|
208 |
+
last_ruling_turn_state = gr.State(0)
|
209 |
+
auto_mode_state = gr.State(False)
|
210 |
+
agent_params_state = gr.State(agent_params)
|
211 |
+
|
212 |
# Status panel
|
213 |
with gr.Row():
|
214 |
turn_counter = gr.Number(label="Turn Count", value=0, interactive=False)
|
|
|
238 |
overseer_out = gr.Textbox(label="Depth Guardian Response", interactive=False)
|
239 |
judge_out = gr.Textbox(label="Judge's Response", interactive=False)
|
240 |
|
241 |
+
# ... [Keep all other tabs the same as before] ...
|
242 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
# Custom CSS
|
244 |
demo.css = """
|
245 |
.convo-container {
|
|
|
276 |
</div>
|
277 |
""")
|
278 |
|
279 |
+
# Event handlers with proper state management
|
280 |
+
qbox.submit(
|
281 |
+
overseer_respond,
|
282 |
+
inputs=[qbox, conversation_state, current_topic_state],
|
283 |
+
outputs=[overseer_out]
|
284 |
+
)
|
285 |
+
|
286 |
+
ruling_qbox.submit(
|
287 |
+
ask_judge,
|
288 |
+
inputs=[ruling_qbox, conversation_state, current_topic_state],
|
289 |
+
outputs=[judge_out]
|
290 |
+
)
|
291 |
+
|
292 |
+
step_btn.click(
|
293 |
+
step,
|
294 |
+
inputs=[topic_input, conversation_state, turn_count_state, current_topic_state, last_ruling_turn_state, agent_params_state],
|
295 |
+
outputs=[
|
296 |
+
convo_display, intervention_display, outsider_display,
|
297 |
+
cultural_display, judge_display, topic_display, turn_counter,
|
298 |
+
agent_status, conversation_state, turn_count_state, current_topic_state,
|
299 |
+
last_ruling_turn_state
|
300 |
+
]
|
301 |
+
)
|
302 |
+
|
303 |
+
auto_btn.click(
|
304 |
+
toggle_auto,
|
305 |
+
inputs=[auto_mode_state],
|
306 |
+
outputs=[auto_btn, auto_mode_state]
|
307 |
+
)
|
308 |
+
|
309 |
+
clear_btn.click(
|
310 |
+
clear_convo,
|
311 |
+
outputs=[
|
312 |
+
convo_display, intervention_display, outsider_display,
|
313 |
+
cultural_display, judge_display, topic_display, turn_counter,
|
314 |
+
agent_status, conversation_state, turn_count_state, current_topic_state,
|
315 |
+
last_ruling_turn_state, overseer_out, judge_out
|
316 |
+
]
|
317 |
+
)
|
318 |
+
|
319 |
+
topic_btn.click(
|
320 |
+
new_topic,
|
321 |
+
inputs=[conversation_state, turn_count_state, current_topic_state],
|
322 |
+
outputs=[
|
323 |
+
convo_display, topic_display, turn_counter, conversation_state,
|
324 |
+
turn_count_state, current_topic_state
|
325 |
+
]
|
326 |
+
)
|
327 |
+
|
328 |
+
ruling_btn.click(
|
329 |
+
request_ruling,
|
330 |
+
inputs=[conversation_state, current_topic_state, turn_count_state, last_ruling_turn_state],
|
331 |
+
outputs=[judge_display, conversation_state, last_ruling_turn_state]
|
332 |
+
)
|
333 |
+
|
334 |
+
analysis_btn.click(
|
335 |
+
run_analysis,
|
336 |
+
inputs=[conversation_state],
|
337 |
+
outputs=[sentiment_display, topics_display, agent_plot]
|
338 |
+
)
|
339 |
+
|
340 |
+
graph_btn.click(
|
341 |
+
generate_knowledge_graph,
|
342 |
+
inputs=[conversation_state],
|
343 |
+
outputs=[graph_display]
|
344 |
+
)
|
345 |
+
|
346 |
+
export_btn.click(
|
347 |
+
export_handler,
|
348 |
+
inputs=[format_radio, conversation_state, current_topic_state, turn_count_state],
|
349 |
+
outputs=[export_result]
|
350 |
+
)
|
351 |
+
|
352 |
+
integrate_btn.click(
|
353 |
+
send_to_webhook,
|
354 |
+
inputs=[webhook_url, conversation_state, current_topic_state, turn_count_state],
|
355 |
+
outputs=[integration_status]
|
356 |
+
)
|
357 |
+
|
358 |
+
submit_btn.click(
|
359 |
+
add_user_contribution,
|
360 |
+
inputs=[user_input, conversation_state],
|
361 |
+
outputs=[convo_display, user_feedback, conversation_state]
|
362 |
+
)
|
363 |
+
|
364 |
+
voting_btn.click(
|
365 |
+
lambda: "β
Your vote has been recorded!",
|
366 |
+
outputs=[user_feedback]
|
367 |
+
)
|
368 |
+
|
369 |
+
flag_btn.click(
|
370 |
+
lambda: "π© Issue flagged for moderator review",
|
371 |
+
outputs=[user_feedback]
|
372 |
+
)
|
373 |
+
|
374 |
+
# Create input list for slider change events
|
375 |
+
slider_inputs = [agent_sliders[f"{agent}_{param}"]
|
376 |
+
for agent in ["Initiator", "Responder", "Guardian", "Provocateur", "Cultural", "Judge"]
|
377 |
+
for param in ["creativity", "critical"]]
|
378 |
+
|
379 |
+
for slider in slider_inputs:
|
380 |
+
slider.change(
|
381 |
+
update_agent_params,
|
382 |
+
inputs=slider_inputs + [agent_params_state],
|
383 |
+
outputs=[agent_params_state]
|
384 |
+
)
|
385 |
|
386 |
demo.launch()
|