File size: 2,229 Bytes
89784d2
 
 
 
 
 
 
b9b41a6
 
 
 
7337f9c
89784d2
b9b41a6
 
7337f9c
 
 
b9b41a6
 
 
 
 
7337f9c
c363697
b9b41a6
 
 
 
c363697
b9b41a6
 
7337f9c
 
 
 
b9b41a6
c363697
 
7337f9c
89784d2
b9b41a6
27e3872
 
 
 
 
 
b9b41a6
 
27e3872
 
b9b41a6
 
27e3872
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c363697
 
7337f9c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# app.py

import gradio as gr
from agents.philosopher import PhilosopherAgent
from agents.historian import HistorianAgent
from agents.hacker import HackerAgent
from agents.comedian import ComedianAgent
from agents.lawyer import LawyerAgent
from agents.scientist import ScientistAgent
from agents.journalist import JournalistAgent
from agents.trader import TraderAgent
from agents.base_agent import ACPMessage

# Initialize all agents
all_agents = [
    PhilosopherAgent(),
    HistorianAgent(),
    HackerAgent(),
    ComedianAgent(),
    LawyerAgent(),
    ScientistAgent(),
    JournalistAgent(),
    TraderAgent()
]

agent_map = {agent.name: agent for agent in all_agents}


def chat(prompt, selected_agents):
    responses = {}
    for name in selected_agents:
        agent = agent_map[name]
        try:
            output = agent.generate([ACPMessage(role="user", content=prompt)])
        except Exception as e:
            output = f"[ERROR] {e}"
        responses[name] = output
    return responses

iface = gr.Interface(
    fn=chat,
    inputs=[
        gr.Textbox(
            label="💬 Ask Anything",
            lines=4,
            placeholder="Ask your question here...",
            elem_id="chat-input"
        ),
        gr.CheckboxGroup(
            choices=list(agent_map.keys()),
            label="🤖 Choose Which Agents to Ask",
            value=list(agent_map.keys())
        )
    ],
    outputs=gr.JSON(label="📢 Agent Responses"),
    title="🧠 Multi-Agent Chatroom",
    description="Ask multiple AI agents across roles like Philosopher, Hacker, Lawyer, etc. Powered by Groq.",
    theme=gr.themes.Soft(
        primary_hue="blue",
        secondary_hue="purple",
        font=[gr.themes.GoogleFont("Fira Sans")],
        radius_size=gr.themes.sizes.radius_md,
        spacing_size=gr.themes.sizes.spacing_md
    ),
    css="""
        #chat-input textarea {
            font-size: 1.1rem;
            padding: 12px;
            background: #1e1e2f;
            color: white;
            border-radius: 12px;
        }
        body {
            background-color: #111827;
            color: white;
        }
        .gr-box {
            border: none;
        }
    """
)

iface.launch()