File size: 1,194 Bytes
28f049d e6b9c0f 28f049d e6b9c0f 28f049d e6b9c0f 28f049d e6b9c0f 28f049d e6b9c0f 28f049d e6b9c0f 28f049d e6b9c0f 28f049d e6b9c0f 7e984a3 e6b9c0f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | from fastapi import FastAPI, Request
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
import os
import uvicorn
# --- Configuraci贸n de la App ---
app = FastAPI()
# 1. Montar el directorio 'static' para servir CSS y JS
# Esto es crucial para que index.html pueda encontrar main.js y style.css
app.mount("/static", StaticFiles(directory="static"), name="static")
# 2. Definir la ruta ra铆z para servir nuestra aplicaci贸n principal
@app.get("/")
async def read_root(request: Request):
"""
Esta es la 煤nica ruta que importa. Sirve el archivo index.html
que contiene toda la l贸gica de Synapse AI.
"""
path = os.path.join("templates", "index.html")
if os.path.exists(path):
return FileResponse(path, media_type="text/html")
return {"error": "index.html not found"}
# 3. Punto de entrada para el servidor cuando se ejecuta en Hugging Face
# Esta secci贸n permite que Hugging Face inicie la aplicaci贸n correctamente.
if __name__ == "__main__":
# Hugging Face Spaces asigna el puerto a trav茅s de la variable de entorno PORT
port = int(os.environ.get("PORT", 7860))
uvicorn.run(app, host="0.0.0.0", port=port) |