Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import asyncio | |
| from textwrap import dedent | |
| from agno.agent import Agent | |
| from agno.models.groq import Groq | |
| from agno.tools.mcp import MCPTools | |
| from agno.tools.thinking import ThinkingTools | |
| from dotenv import load_dotenv | |
| import os | |
| # Charger la clé API | |
| load_dotenv() | |
| GROQ_API_KEY = os.getenv("GROQ_API_KEY") | |
| if not GROQ_API_KEY: | |
| raise ValueError("Veuillez définir la variable GROQ_API_KEY.") | |
| os.environ["GROQ_API_KEY"] = GROQ_API_KEY | |
| # Fonction async appelée par Gradio | |
| async def search_airbnb(query: str) -> str: | |
| async with MCPTools("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt") as mcp_tools: | |
| agent = Agent( | |
| model=Groq(id="meta-llama/llama-4-scout-17b-16e-instruct"), | |
| tools=[ThinkingTools(), mcp_tools], | |
| instructions=dedent(""" | |
| ## Instructions générales | |
| - Utilise l'outil 'think' pour planifier les étapes. | |
| - Présente 10 annonces Airbnb sous forme de tableau avec liens. | |
| - Valide les résultats avant de répondre à l'utilisateur. | |
| """), | |
| add_datetime_to_instructions=True, | |
| show_tool_calls=False, | |
| markdown=True, | |
| ) | |
| result = await agent.arun(query) | |
| return result.content | |
| # Interface Gradio qui supporte nativement async | |
| demo = gr.Interface( | |
| fn=search_airbnb, | |
| inputs=gr.Textbox(label="Votre requête", lines=4, placeholder="Ex: logement 1 chambre à Paris du 5 au 15 août..."), | |
| outputs=gr.Markdown(label="Résultat"), | |
| title="🏠 Agent Airbnb intelligent (MCP + Llama 4)", | |
| description="Un assistant LLM intelligent pour chercher les meilleures annonces Airbnb selon vos critères.", | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |