mys's picture
Upload folder using huggingface_hub
1c75c98 verified
# tracklight_server/api/dashboard.py
from fastapi import APIRouter, Depends, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from ..db import duckdb
from .auth import verify_token
import os
router = APIRouter()
# Get the absolute path to the templates directory
SERVER_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATES_DIR = os.path.join(SERVER_DIR, "templates")
templates = Jinja2Templates(directory=TEMPLATES_DIR)
@router.get("/login", response_class=HTMLResponse)
async def get_login_page(request: Request):
"""
Serves the login page.
"""
return templates.TemplateResponse("login.html", {"request": request})
@router.get("/dashboard", response_class=HTMLResponse)
async def get_dashboard(request: Request):
"""
Serves the main dashboard page with a list of projects.
"""
projects = duckdb.get_projects()
return templates.TemplateResponse("project_list.html", {"request": request, "projects": projects})
@router.get("/project/{project_name}", response_class=HTMLResponse)
async def get_project_page(request: Request, project_name: str, user: str):
"""
Serves the project-specific page with a list of runs.
"""
runs = duckdb.get_runs(project_name, user)
return templates.TemplateResponse("dashboard.html", {"request": request, "project": project_name, "user": user, "runs": runs})
@router.get("/api/metrics")
async def get_metrics(run_id: str, token: str = Depends(verify_token)):
"""
Returns metrics and config for a given run.
"""
metrics = duckdb.get_metrics_for_run(run_id)
config = duckdb.get_config_for_run(run_id)
return {"metrics": metrics, "config": config}