-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add Gradio UI for Airbnb Booking Assistant #434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,33 @@ flowchart LR | |
| - OpenAI API key (for the agent's LLM) | ||
| </Note> | ||
|
|
||
| ## Gradio UI | ||
|
|
||
| ```python | ||
| from praisonaiagents import Agent, MCP | ||
| import gradio as gr | ||
|
|
||
| def search_airbnb(query): | ||
| agent = Agent( | ||
| instructions="You help book apartments on Airbnb.", | ||
| llm="gpt-4o-mini", | ||
| tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt") | ||
| ) | ||
| result = agent.start(query) | ||
| return f"## Airbnb Search Results\n\n{result}" | ||
|
Comment on lines
+76
to
+83
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding error handling to gracefully manage potential issues during agent initialization or API calls. For example, wrap the |
||
|
|
||
| demo = gr.Interface( | ||
| fn=search_airbnb, | ||
| inputs=gr.Textbox(placeholder="I want to book an apartment in Paris for 2 nights..."), | ||
| outputs=gr.Markdown(), | ||
| title="Airbnb Booking Assistant", | ||
| description="Enter your booking requirements below:" | ||
| ) | ||
|
|
||
| if __name__ == "__main__": | ||
| demo.launch() | ||
| ``` | ||
|
|
||
| ## Features | ||
|
|
||
| <CardGroup cols={2}> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| from praisonaiagents import Agent, MCP | ||
| import gradio as gr | ||
|
|
||
| def search_airbnb(query): | ||
| agent = Agent( | ||
| instructions="You help book apartments on Airbnb.", | ||
| llm="gpt-4o-mini", | ||
| tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt") | ||
|
Comment on lines
+5
to
+8
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The LLM and tool configurations are hardcoded. Consider making these configurable via environment variables or a configuration file to allow users to easily change the settings without modifying the code. llm = os.getenv("LLM_MODEL", "gpt-4o-mini")
tools_command = os.getenv("AIRBNB_MCP_COMMAND", "npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
agent = Agent(
instructions="You help book apartments on Airbnb.",
llm=llm,
tools=MCP(tools_command)
) |
||
| ) | ||
| result = agent.start(query) | ||
| return f"## Airbnb Search Results\n\n{result}" | ||
|
Comment on lines
+4
to
+11
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding error handling to gracefully manage potential issues during agent initialization or API calls. For example, wrap the try:
result = agent.start(query)
except Exception as e:
return f"## Airbnb Search Results\n\nError: {str(e)}"
return f"## Airbnb Search Results\n\n{result}" |
||
|
|
||
| demo = gr.Interface( | ||
| fn=search_airbnb, | ||
| inputs=gr.Textbox(placeholder="I want to book an apartment in Paris for 2 nights..."), | ||
| outputs=gr.Markdown(), | ||
| title="Airbnb Booking Assistant", | ||
| description="Enter your booking requirements below:" | ||
| ) | ||
|
|
||
| if __name__ == "__main__": | ||
| demo.launch() | ||
|
Comment on lines
+1
to
+22
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Gradio UI code is duplicated in # In a new file, e.g., gradio_app.py:
# def create_gradio_app():
# from praisonaiagents import Agent, MCP
# import gradio as gr
#
# def search_airbnb(query):
# agent = Agent(
# instructions="You help book apartments on Airbnb.",
# llm="gpt-4o-mini",
# tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
# )
# result = agent.start(query)
# return f"## Airbnb Search Results\n\n{result}"
#
# demo = gr.Interface(
# fn=search_airbnb,
# inputs=gr.Textbox(placeholder="I want to book an apartment in Paris for 2 nights..."),
# outputs=gr.Markdown(),
# title="Airbnb Booking Assistant",
# description="Enter your booking requirements below:"
# )
# return demo
# if __name__ == "__main__":
# demo = create_gradio_app()
# demo.launch()
# Then, in both airbnb.mdx and ui.py:
# from gradio_app import create_gradio_app
# demo = create_gradio_app()
# if __name__ == "__main__":
# demo.launch() |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LLM and tool configurations are hardcoded. Consider making these configurable via environment variables or a configuration file to allow users to easily change the settings without modifying the code.