Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,59 +1,62 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from swarm import Swarm, Agent
|
| 3 |
|
| 4 |
-
# Initialize Swarm client
|
| 5 |
client = Swarm()
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
def transfer_to_agent_b():
|
| 9 |
-
return agent_b
|
| 10 |
-
|
| 11 |
-
def transfer_to_agent_c():
|
| 12 |
-
return agent_c
|
| 13 |
-
|
| 14 |
def transfer_to_spanish_agent():
|
| 15 |
-
"""Transfer Spanish
|
| 16 |
return spanish_agent
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
instructions="You are a helpful agent.",
|
| 22 |
-
functions=[transfer_to_agent_b],
|
| 23 |
-
)
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
functions=[transfer_to_spanish_agent],
|
| 29 |
-
)
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
)
|
| 35 |
|
|
|
|
| 36 |
spanish_agent = Agent(
|
| 37 |
name="Spanish Agent",
|
| 38 |
-
instructions="You only speak Spanish.",
|
| 39 |
)
|
| 40 |
|
|
|
|
| 41 |
english_agent = Agent(
|
| 42 |
name="English Agent",
|
| 43 |
-
instructions="You only speak English.",
|
| 44 |
)
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
#
|
| 50 |
-
def
|
| 51 |
messages = [{"role": "user", "content": user_input}]
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
return response.messages[-1]["content"]
|
| 54 |
|
| 55 |
-
# Create Gradio interface
|
| 56 |
-
iface = gr.Interface(fn=
|
| 57 |
|
| 58 |
# Launch the interface
|
| 59 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from swarm import Swarm, Agent
|
| 3 |
|
|
|
|
| 4 |
client = Swarm()
|
| 5 |
|
| 6 |
+
# Agent functions for task delegation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
def transfer_to_spanish_agent():
|
| 8 |
+
"""Transfer Spanish-speaking users to the Spanish agent."""
|
| 9 |
return spanish_agent
|
| 10 |
|
| 11 |
+
def transfer_to_english_agent():
|
| 12 |
+
"""Transfer English-speaking users to the English agent."""
|
| 13 |
+
return english_agent
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
def verify_order_task():
|
| 16 |
+
"""Handle order verification task."""
|
| 17 |
+
return order_verifier_agent
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
# General agent that identifies the user's language
|
| 20 |
+
general_agent = Agent(
|
| 21 |
+
name="General Agent",
|
| 22 |
+
instructions="Assist the user based on language and delegate tasks if needed.",
|
| 23 |
+
functions=[transfer_to_spanish_agent, transfer_to_english_agent],
|
| 24 |
)
|
| 25 |
|
| 26 |
+
# Spanish-specific agent
|
| 27 |
spanish_agent = Agent(
|
| 28 |
name="Spanish Agent",
|
| 29 |
+
instructions="You only speak Spanish. Help with customer support in Spanish.",
|
| 30 |
)
|
| 31 |
|
| 32 |
+
# English-specific agent
|
| 33 |
english_agent = Agent(
|
| 34 |
name="English Agent",
|
| 35 |
+
instructions="You only speak English. Help with customer support in English.",
|
| 36 |
)
|
| 37 |
|
| 38 |
+
# Task-specific agent for verifying orders
|
| 39 |
+
order_verifier_agent = Agent(
|
| 40 |
+
name="Order Verifier",
|
| 41 |
+
instructions="Verify customer orders and check their status.",
|
| 42 |
+
)
|
| 43 |
|
| 44 |
+
# Creating the Gradio interface function
|
| 45 |
+
def customer_support_demo(user_input):
|
| 46 |
messages = [{"role": "user", "content": user_input}]
|
| 47 |
+
|
| 48 |
+
# Check for language and delegate to the appropriate agent
|
| 49 |
+
if "hola" in user_input.lower():
|
| 50 |
+
response = client.run(agent=spanish_agent, messages=messages)
|
| 51 |
+
elif "hello" in user_input.lower():
|
| 52 |
+
response = client.run(agent=english_agent, messages=messages)
|
| 53 |
+
else:
|
| 54 |
+
response = client.run(agent=general_agent, messages=messages)
|
| 55 |
+
|
| 56 |
return response.messages[-1]["content"]
|
| 57 |
|
| 58 |
+
# Create the Gradio interface
|
| 59 |
+
iface = gr.Interface(fn=customer_support_demo, inputs="text", outputs="text", live=True)
|
| 60 |
|
| 61 |
# Launch the interface
|
| 62 |
iface.launch()
|