File size: 3,185 Bytes
dcef84c
 
 
 
 
fa7c33d
dcef84c
fa7c33d
dcef84c
 
fa7c33d
 
 
dcef84c
99d411f
 
 
 
d1d5a30
 
 
 
fa7c33d
 
 
dcef84c
fa7c33d
 
 
 
d1d5a30
dcef84c
 
fa7c33d
dcef84c
 
fa7c33d
dcef84c
 
fa7c33d
dcef84c
 
fa7c33d
dcef84c
 
99d411f
 
 
 
 
 
d1d5a30
 
 
 
 
 
fa7c33d
 
 
 
 
dcef84c
fa7c33d
 
dcef84c
fa7c33d
 
 
 
 
 
99d411f
 
d1d5a30
 
fa7c33d
 
 
dcef84c
 
99d411f
1038bab
 
 
 
 
 
 
 
dcef84c
 
 
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
85
86
87
88
89
90
91
92
93
94
import gradio as gr
from swarm import Swarm, Agent

client = Swarm()

# Agent functions for task delegation
def transfer_to_spanish_agent():
    """Transfer Spanish-speaking users to the Spanish agent."""
    return spanish_agent

def transfer_to_english_agent():
    """Transfer English-speaking users to the English agent."""
    return english_agent

def transfer_to_hindi_agent():
    """Transfer Hindi-speaking users to the Hindi agent."""
    return hindi_agent

def transfer_to_filipino_agent():
    """Transfer Filipino-speaking users to the Filipino agent."""
    return filipino_agent

def verify_order_task():
    """Handle order verification task."""
    return order_verifier_agent

# General agent that identifies the user's language
general_agent = Agent(
    name="General Agent",
    instructions="Assist the user based on language and delegate tasks if needed.",
    functions=[transfer_to_spanish_agent, transfer_to_english_agent, transfer_to_hindi_agent, transfer_to_filipino_agent],
)

# Spanish-specific agent
spanish_agent = Agent(
    name="Spanish Agent",
    instructions="You only speak Spanish. Help with customer support in Spanish.",
)

# English-specific agent
english_agent = Agent(
    name="English Agent",
    instructions="You only speak English. Help with customer support in English.",
)

# Hindi-specific agent
hindi_agent = Agent(
    name="Hindi Agent",
    instructions="You only speak Hindi. Help with customer support in Hindi.",
)

# Filipino-specific agent
filipino_agent = Agent(
    name="Filipino Agent",
    instructions="You only speak Filipino/Tagalog. Help with customer support in Filipino.",
)

# Task-specific agent for verifying orders
order_verifier_agent = Agent(
    name="Order Verifier",
    instructions="Verify customer orders and check their status.",
)

# Creating the Gradio interface function
def customer_support_demo(user_input):
    messages = [{"role": "user", "content": user_input}]
    
    # Check for language and delegate to the appropriate agent
    if "hola" in user_input.lower():
        response = client.run(agent=spanish_agent, messages=messages)
    elif "hello" in user_input.lower():
        response = client.run(agent=english_agent, messages=messages)
    elif "नमस्ते" in user_input.lower():
        response = client.run(agent=hindi_agent, messages=messages)
    elif "kamusta" in user_input.lower() or "magandang araw" in user_input.lower():
        response = client.run(agent=filipino_agent, messages=messages)
    else:
        response = client.run(agent=general_agent, messages=messages)
    
    return response.messages[-1]["content"]

# Create the Gradio interface with a label and description
iface = gr.Interface(
    fn=customer_support_demo,
    inputs="text",
    outputs="text",
    live=True,
    title="Global Customer Support System",
    description="This is a multi-agent system designed to provide global customer support in multiple languages. It detects the language of your input and directs you to the appropriate agent. If needed, the agents can delegate tasks to specialized agents, such as order verification.",
)

# Launch the interface
iface.launch()