Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,46 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from server import mcp # Tu servidor MCP original
|
| 4 |
|
| 5 |
-
app = FastAPI()
|
| 6 |
|
| 7 |
-
# Interfaz Gradio
|
| 8 |
-
|
| 9 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
app
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
# app.
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
if __name__ == "__main__":
|
| 21 |
import uvicorn
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
+
from fastapi.responses import RedirectResponse
|
| 3 |
import gradio as gr
|
| 4 |
from server import mcp # Tu servidor MCP original
|
| 5 |
|
| 6 |
+
app = FastAPI(title="MCP Server")
|
| 7 |
|
| 8 |
+
# Interfaz Gradio más completa
|
| 9 |
+
def create_demo():
|
| 10 |
+
with gr.Blocks(title="MCP Dashboard") as demo:
|
| 11 |
+
gr.Markdown("# 🚀 MCP Server Dashboard")
|
| 12 |
+
gr.Markdown("Bienvenido al panel de control del servidor MCP")
|
| 13 |
+
|
| 14 |
+
with gr.Row():
|
| 15 |
+
status = gr.Textbox(label="Estado del servidor", value="✅ Servidor activo")
|
| 16 |
+
btn = gr.Button("Actualizar estado")
|
| 17 |
+
|
| 18 |
+
def update_status():
|
| 19 |
+
return "✅ Servidor activo - Última verificación: " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 20 |
+
|
| 21 |
+
btn.click(update_status, outputs=status)
|
| 22 |
+
|
| 23 |
+
gr.Markdown("### Endpoints disponibles:")
|
| 24 |
+
gr.Markdown("- `/get_document_info` - Obtener información de documentos")
|
| 25 |
+
gr.Markdown("- `/sse` - Stream de eventos")
|
| 26 |
+
|
| 27 |
+
return demo
|
| 28 |
|
| 29 |
+
# Configuración especial para Hugging Face Spaces
|
| 30 |
+
@app.get("/")
|
| 31 |
+
async def root(request: Request):
|
| 32 |
+
# Redirige a /gradio para evitar el bucle de redirección
|
| 33 |
+
return RedirectResponse(url="/gradio")
|
| 34 |
|
| 35 |
+
# Monta Gradio en una ruta específica
|
| 36 |
+
gradio_app = create_demo()
|
| 37 |
+
app = gr.mount_gradio_app(app, gradio_app, path="/gradio")
|
| 38 |
|
| 39 |
+
# Si mcp es un router FastAPI
|
| 40 |
+
# app.include_router(mcp, prefix="/api")
|
| 41 |
+
|
| 42 |
+
# Si mcp es una aplicación FastAPI completa
|
| 43 |
+
# app.mount("/api", mcp)
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
| 46 |
import uvicorn
|