Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -378,7 +378,7 @@ async def query_context(
|
|
| 378 |
##### MCP AGENT #####
|
| 379 |
sse_url = "https://pharma-ia-gradio-mcp-server.hf.space/gradio_api/mcp/sse"
|
| 380 |
|
| 381 |
-
# Crear instancia del agente (
|
| 382 |
mcp_agent = MCPAgent(sse_url, HF_TOKEN, llm)
|
| 383 |
|
| 384 |
# Historial de chat
|
|
@@ -485,42 +485,41 @@ with gr.Blocks(title="Herramientas MCP") as tools_tab:
|
|
| 485 |
|
| 486 |
# Creamos el Agente MCP (puedes personalizar esto seg煤n necesites)
|
| 487 |
with gr.Blocks(title="Agente MCP") as agent_tab:
|
| 488 |
-
|
| 489 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 490 |
|
|
|
|
| 491 |
with gr.Row():
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
msg = gr.Textbox(
|
| 500 |
-
label="Mensaje",
|
| 501 |
-
placeholder="Escribe tu pregunta aqu铆...",
|
| 502 |
-
container=False
|
| 503 |
-
)
|
| 504 |
-
btn = gr.Button("Enviar")
|
| 505 |
-
clear = gr.ClearButton([msg, chatbot])
|
| 506 |
-
|
| 507 |
-
with gr.Column(scale=1):
|
| 508 |
-
gr.Markdown("### Herramientas Disponibles")
|
| 509 |
-
tools_info = gr.JSON(label="Herramientas", value=[])
|
| 510 |
|
| 511 |
-
|
|
|
|
|
|
|
| 512 |
async def init_agent():
|
| 513 |
-
|
| 514 |
-
return
|
| 515 |
-
|
| 516 |
-
agent_tab.load(init_agent, outputs=[tools_info])
|
| 517 |
|
| 518 |
-
|
|
|
|
|
|
|
| 519 |
msg.submit(
|
| 520 |
chat_with_agent,
|
| 521 |
inputs=[msg, chatbot],
|
| 522 |
outputs=[chatbot]
|
| 523 |
-
)
|
|
|
|
| 524 |
btn.click(
|
| 525 |
chat_with_agent,
|
| 526 |
inputs=[msg, chatbot],
|
|
|
|
| 378 |
##### MCP AGENT #####
|
| 379 |
sse_url = "https://pharma-ia-gradio-mcp-server.hf.space/gradio_api/mcp/sse"
|
| 380 |
|
| 381 |
+
# Crear instancia del agente (con llm definido)
|
| 382 |
mcp_agent = MCPAgent(sse_url, HF_TOKEN, llm)
|
| 383 |
|
| 384 |
# Historial de chat
|
|
|
|
| 485 |
|
| 486 |
# Creamos el Agente MCP (puedes personalizar esto seg煤n necesites)
|
| 487 |
with gr.Blocks(title="Agente MCP") as agent_tab:
|
| 488 |
+
# Chat principal
|
| 489 |
+
chatbot = gr.Chatbot(
|
| 490 |
+
label="Chat con el Agente MCP",
|
| 491 |
+
height=600,
|
| 492 |
+
bubble_full_width=True,
|
| 493 |
+
render_markdown=True,
|
| 494 |
+
show_label=False
|
| 495 |
+
)
|
| 496 |
|
| 497 |
+
# Barra de entrada
|
| 498 |
with gr.Row():
|
| 499 |
+
msg = gr.Textbox(
|
| 500 |
+
placeholder="Escribe tu mensaje aqu铆...",
|
| 501 |
+
container=False,
|
| 502 |
+
scale=9,
|
| 503 |
+
autofocus=True
|
| 504 |
+
)
|
| 505 |
+
btn = gr.Button("Enviar", scale=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 506 |
|
| 507 |
+
clear = gr.ClearButton([msg, chatbot], value="Limpiar conversaci贸n")
|
| 508 |
+
|
| 509 |
+
# Inicializaci贸n del agente (sin mostrar herramientas)
|
| 510 |
async def init_agent():
|
| 511 |
+
await mcp_agent.initialize()
|
| 512 |
+
return gr.Info("Agente listo para conversar")
|
|
|
|
|
|
|
| 513 |
|
| 514 |
+
agent_tab.load(init_agent)
|
| 515 |
+
|
| 516 |
+
# Manejo de interacciones
|
| 517 |
msg.submit(
|
| 518 |
chat_with_agent,
|
| 519 |
inputs=[msg, chatbot],
|
| 520 |
outputs=[chatbot]
|
| 521 |
+
).then(lambda: "", None, [msg])
|
| 522 |
+
|
| 523 |
btn.click(
|
| 524 |
chat_with_agent,
|
| 525 |
inputs=[msg, chatbot],
|