Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,45 +2,47 @@ 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
|
| 9 |
def create_demo():
|
| 10 |
with gr.Blocks(title="MCP Dashboard") as demo:
|
| 11 |
gr.Markdown("# 🚀 MCP Server Dashboard")
|
| 12 |
-
gr.
|
|
|
|
| 13 |
|
| 14 |
with gr.Row():
|
| 15 |
-
status = gr.Textbox(label="Estado
|
| 16 |
-
btn = gr.Button("Actualizar
|
| 17 |
|
| 18 |
def update_status():
|
| 19 |
-
return "✅ Servidor activo
|
| 20 |
|
| 21 |
btn.click(update_status, outputs=status)
|
| 22 |
|
| 23 |
gr.Markdown("### Endpoints disponibles:")
|
| 24 |
-
gr.Markdown("- `/get_document_info` -
|
| 25 |
gr.Markdown("- `/sse` - Stream de eventos")
|
| 26 |
|
| 27 |
return demo
|
| 28 |
|
| 29 |
-
#
|
| 30 |
@app.get("/")
|
| 31 |
async def root(request: Request):
|
| 32 |
-
#
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
#
|
| 36 |
gradio_app = create_demo()
|
| 37 |
app = gr.mount_gradio_app(app, gradio_app, path="/gradio")
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
# app.include_router(mcp
|
| 41 |
-
|
| 42 |
-
# Si mcp es una aplicación FastAPI completa
|
| 43 |
-
# app.mount("/api", mcp)
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
| 46 |
import uvicorn
|
|
|
|
| 2 |
from fastapi.responses import RedirectResponse
|
| 3 |
import gradio as gr
|
| 4 |
from server import mcp # Tu servidor MCP original
|
| 5 |
+
import datetime
|
| 6 |
|
| 7 |
app = FastAPI(title="MCP Server")
|
| 8 |
|
| 9 |
+
# Interfaz Gradio mejorada
|
| 10 |
def create_demo():
|
| 11 |
with gr.Blocks(title="MCP Dashboard") as demo:
|
| 12 |
gr.Markdown("# 🚀 MCP Server Dashboard")
|
| 13 |
+
with gr.Row():
|
| 14 |
+
gr.Markdown("Bienvenido al panel de control del servidor MCP")
|
| 15 |
|
| 16 |
with gr.Row():
|
| 17 |
+
status = gr.Textbox(label="Estado", value="✅ Servidor activo")
|
| 18 |
+
btn = gr.Button("Actualizar")
|
| 19 |
|
| 20 |
def update_status():
|
| 21 |
+
return f"✅ Servidor activo (Última verificación: {datetime.datetime.now().strftime('%H:%M:%S')}"
|
| 22 |
|
| 23 |
btn.click(update_status, outputs=status)
|
| 24 |
|
| 25 |
gr.Markdown("### Endpoints disponibles:")
|
| 26 |
+
gr.Markdown("- `/get_document_info` - Información de documentos")
|
| 27 |
gr.Markdown("- `/sse` - Stream de eventos")
|
| 28 |
|
| 29 |
return demo
|
| 30 |
|
| 31 |
+
# Redirección inteligente para Hugging Face Spaces
|
| 32 |
@app.get("/")
|
| 33 |
async def root(request: Request):
|
| 34 |
+
# Verifica si el acceso viene de la página principal del Space
|
| 35 |
+
if "hf.space" in request.headers.get("referer", ""):
|
| 36 |
+
return RedirectResponse(url="/gradio")
|
| 37 |
+
return {"message": "MCP Server API", "docs": "/gradio"}
|
| 38 |
|
| 39 |
+
# Montaje de Gradio
|
| 40 |
gradio_app = create_demo()
|
| 41 |
app = gr.mount_gradio_app(app, gradio_app, path="/gradio")
|
| 42 |
|
| 43 |
+
# Integración con MCP (elige una opción)
|
| 44 |
+
# app.include_router(mcp.router) # Si usa routers
|
| 45 |
+
app.mount("/api", mcp.app) # Si es una app FastAPI
|
|
|
|
|
|
|
| 46 |
|
| 47 |
if __name__ == "__main__":
|
| 48 |
import uvicorn
|