Update app.py
Browse files
app.py
CHANGED
|
@@ -16,22 +16,26 @@ retry_counter = {"count": 0}
|
|
| 16 |
|
| 17 |
def pre_hook(fc: FunctionCall):
|
| 18 |
"""Pre-hook for tool calls. In this web UI, human approval is handled in the console version."""
|
|
|
|
| 19 |
return
|
| 20 |
|
| 21 |
# Tools definitions
|
| 22 |
@tool(pre_hook=pre_hook)
|
| 23 |
def get_fact(fact: str) -> Iterator[str]:
|
|
|
|
| 24 |
yield fact
|
| 25 |
|
| 26 |
@tool(pre_hook=pre_hook)
|
| 27 |
def get_quote(quote: str) -> Iterator[str]:
|
|
|
|
| 28 |
yield quote
|
| 29 |
|
| 30 |
@tool(pre_hook=pre_hook)
|
| 31 |
def get_joke(joke: str) -> Iterator[str]:
|
|
|
|
| 32 |
yield joke
|
| 33 |
|
| 34 |
-
# Initialize the agent
|
| 35 |
agent = Agent(
|
| 36 |
description="An agent that shares fun stuff like facts, quotes, or jokes.",
|
| 37 |
instructions="""
|
|
@@ -39,14 +43,11 @@ agent = Agent(
|
|
| 39 |
- a fun fact
|
| 40 |
- a motivational quote
|
| 41 |
- or a joke
|
| 42 |
-
|
| 43 |
When you get a response from a tool:
|
| 44 |
1. For facts, start with \"Here's an interesting fact: \" followed by the tool's output
|
| 45 |
2. For quotes, start with \"Here's a motivational quote: \" followed by the tool's output
|
| 46 |
3. For jokes, start with \"Here's a joke: \" followed by the tool's output
|
| 47 |
-
|
| 48 |
Ask the user before sharing, and retry only if they say so. Stop after 3 retries.
|
| 49 |
-
|
| 50 |
If you have no tools to use, you should say \"I don't have any tools to use.\"
|
| 51 |
""",
|
| 52 |
tools=[get_fact, get_quote, get_joke],
|
|
@@ -69,14 +70,15 @@ def respond(message: str) -> str:
|
|
| 69 |
except Exception as e:
|
| 70 |
return f"Error: {e}"
|
| 71 |
|
| 72 |
-
# Build the Gradio interface
|
| 73 |
iface = gr.Interface(
|
| 74 |
fn=respond,
|
| 75 |
-
inputs=gr.
|
| 76 |
-
outputs=
|
| 77 |
title="Human-in-the-Loop AI Agent",
|
| 78 |
description="Ask the agent to share a fun fact, motivational quote, or joke. The agent will use Nebius and Agno under the hood.",
|
| 79 |
)
|
| 80 |
|
|
|
|
| 81 |
if __name__ == "__main__":
|
| 82 |
iface.launch()
|
|
|
|
| 16 |
|
| 17 |
def pre_hook(fc: FunctionCall):
|
| 18 |
"""Pre-hook for tool calls. In this web UI, human approval is handled in the console version."""
|
| 19 |
+
# This function is a placeholder for this example, as the UI handles interaction.
|
| 20 |
return
|
| 21 |
|
| 22 |
# Tools definitions
|
| 23 |
@tool(pre_hook=pre_hook)
|
| 24 |
def get_fact(fact: str) -> Iterator[str]:
|
| 25 |
+
"""Provides a fun fact."""
|
| 26 |
yield fact
|
| 27 |
|
| 28 |
@tool(pre_hook=pre_hook)
|
| 29 |
def get_quote(quote: str) -> Iterator[str]:
|
| 30 |
+
"""Provides a motivational quote."""
|
| 31 |
yield quote
|
| 32 |
|
| 33 |
@tool(pre_hook=pre_hook)
|
| 34 |
def get_joke(joke: str) -> Iterator[str]:
|
| 35 |
+
"""Provides a joke."""
|
| 36 |
yield joke
|
| 37 |
|
| 38 |
+
# Initialize the agent
|
| 39 |
agent = Agent(
|
| 40 |
description="An agent that shares fun stuff like facts, quotes, or jokes.",
|
| 41 |
instructions="""
|
|
|
|
| 43 |
- a fun fact
|
| 44 |
- a motivational quote
|
| 45 |
- or a joke
|
|
|
|
| 46 |
When you get a response from a tool:
|
| 47 |
1. For facts, start with \"Here's an interesting fact: \" followed by the tool's output
|
| 48 |
2. For quotes, start with \"Here's a motivational quote: \" followed by the tool's output
|
| 49 |
3. For jokes, start with \"Here's a joke: \" followed by the tool's output
|
|
|
|
| 50 |
Ask the user before sharing, and retry only if they say so. Stop after 3 retries.
|
|
|
|
| 51 |
If you have no tools to use, you should say \"I don't have any tools to use.\"
|
| 52 |
""",
|
| 53 |
tools=[get_fact, get_quote, get_joke],
|
|
|
|
| 70 |
except Exception as e:
|
| 71 |
return f"Error: {e}"
|
| 72 |
|
| 73 |
+
# Build the Gradio interface with the corrected syntax
|
| 74 |
iface = gr.Interface(
|
| 75 |
fn=respond,
|
| 76 |
+
inputs=gr.Textbox(lines=2, placeholder="Ask for a fact, quote, or joke..."),
|
| 77 |
+
outputs=gr.Markdown(),
|
| 78 |
title="Human-in-the-Loop AI Agent",
|
| 79 |
description="Ask the agent to share a fun fact, motivational quote, or joke. The agent will use Nebius and Agno under the hood.",
|
| 80 |
)
|
| 81 |
|
| 82 |
+
# Launch the application
|
| 83 |
if __name__ == "__main__":
|
| 84 |
iface.launch()
|