Translate UI to English and add PWA support
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""
|
||||
LLM Monitor - Dashboard per controllare i modelli caricati in Ollama
|
||||
Entry point dell'applicazione FastAPI
|
||||
LLM Monitor - Dashboard to monitor Ollama models.
|
||||
FastAPI application entry point.
|
||||
"""
|
||||
|
||||
import logging
|
||||
@@ -12,26 +12,26 @@ from fastapi.openapi.docs import get_redoc_html
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
# Configurazione logging
|
||||
# Logging configuration
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Importare le rotte
|
||||
# Import API routes
|
||||
from app.api.health import router as health_router
|
||||
from app.api.models import router as models_router
|
||||
from app.config import settings
|
||||
|
||||
# Creare l'app FastAPI
|
||||
# Create FastAPI app
|
||||
app = FastAPI(
|
||||
title="LLM Monitor API",
|
||||
description="Dashboard per il monitoraggio dei modelli LLM in Ollama",
|
||||
description="Dashboard and API for monitoring Ollama LLM models",
|
||||
version="1.0.0",
|
||||
docs_url="/docs",
|
||||
redoc_url=None,
|
||||
openapi_url="/openapi.json"
|
||||
)
|
||||
|
||||
# Configurare CORS
|
||||
# Configure CORS
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=settings.CORS_ORIGINS.split(","),
|
||||
@@ -40,44 +40,56 @@ app.add_middleware(
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# Registrare le rotte API
|
||||
# Register API routes
|
||||
app.include_router(health_router, prefix="/api/v1", tags=["health"])
|
||||
app.include_router(models_router, prefix="/api/v1", tags=["models"])
|
||||
|
||||
# Servire i file statici
|
||||
# Serve static files
|
||||
static_path = Path(__file__).parent / "app" / "web" / "static"
|
||||
if static_path.exists():
|
||||
app.mount("/static", StaticFiles(directory=static_path), name="static")
|
||||
|
||||
# Servire la dashboard web
|
||||
# Serve web pages
|
||||
templates_path = Path(__file__).parent / "app" / "web" / "templates"
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
"""Pagina principale: modelli residenti in memoria (ollama ps)."""
|
||||
"""Primary page: models currently loaded in memory (ollama ps)."""
|
||||
return FileResponse(templates_path / "models_running.html")
|
||||
|
||||
@app.get("/dashboard")
|
||||
async def dashboard():
|
||||
"""Alias legacy della pagina principale."""
|
||||
"""Legacy alias for the primary page."""
|
||||
return FileResponse(templates_path / "models_running.html")
|
||||
|
||||
|
||||
@app.get("/models-available")
|
||||
async def models_available_page():
|
||||
"""Pagina modelli disponibili su disco."""
|
||||
"""Page listing models available on disk."""
|
||||
return FileResponse(templates_path / "index.html")
|
||||
|
||||
|
||||
@app.get("/models-running")
|
||||
async def models_running_page():
|
||||
"""Pagina dedicata ai modelli residenti in memoria (ollama ps)."""
|
||||
"""Page dedicated to models resident in memory (ollama ps)."""
|
||||
return FileResponse(templates_path / "models_running.html")
|
||||
|
||||
|
||||
@app.get("/manifest.webmanifest", include_in_schema=False)
|
||||
async def web_manifest():
|
||||
"""PWA web manifest."""
|
||||
return FileResponse(static_path / "manifest.webmanifest", media_type="application/manifest+json")
|
||||
|
||||
|
||||
@app.get("/service-worker.js", include_in_schema=False)
|
||||
async def service_worker():
|
||||
"""PWA service worker with root scope."""
|
||||
return FileResponse(static_path / "js" / "service-worker.js", media_type="application/javascript")
|
||||
|
||||
|
||||
@app.get("/redoc", include_in_schema=False)
|
||||
async def redoc_html():
|
||||
"""Documentazione ReDoc con bundle stabile (evita dipendenza da redoc@next)."""
|
||||
"""ReDoc documentation using a stable bundle."""
|
||||
return get_redoc_html(
|
||||
openapi_url=app.openapi_url,
|
||||
title=f"{app.title} - ReDoc",
|
||||
@@ -88,18 +100,18 @@ async def redoc_html():
|
||||
|
||||
@app.get("/favicon.ico", include_in_schema=False)
|
||||
async def favicon():
|
||||
"""Favicon dell'applicazione."""
|
||||
"""Application favicon."""
|
||||
return FileResponse(static_path / "favicon.ico")
|
||||
|
||||
# Event hooks
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
logger.info("🚀 LLM Monitor avviato")
|
||||
logger.info(f"📊 Ollama host: {settings.OLLAMA_HOST}")
|
||||
logger.info("LLM Monitor started")
|
||||
logger.info(f"Ollama host: {settings.OLLAMA_HOST}")
|
||||
|
||||
@app.on_event("shutdown")
|
||||
async def shutdown_event():
|
||||
logger.info("🛑 LLM Monitor arrestato")
|
||||
logger.info("LLM Monitor stopped")
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
Reference in New Issue
Block a user