Spaces:
Sleeping
Sleeping
Download app.py from nbroad/compare-openrouter-providers: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/spaces/nbroad/compare-openrouter-providers/resolve/main/app.py
- Command line
-
hf download hf://spaces/nbroad/compare-openrouter-providers/app.py
-
curl -L -o app.py https://huggingface.co/spaces/nbroad/compare-openrouter-providers/resolve/main/app.py
1.49 kB
| import asyncio | |
| from pathlib import Path | |
| from fastapi import FastAPI, Request | |
| from fastapi.responses import HTMLResponse | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.templating import Jinja2Templates | |
| from fetch_data import refresh_data | |
| app = FastAPI(title="OpenRouter Provider Dashboard") | |
| # Get the directory where this file is located | |
| BASE_DIR = Path(__file__).parent | |
| # Set up templates directory | |
| templates = Jinja2Templates(directory=str(BASE_DIR / "templates")) | |
| # Data directory - create if missing so refresh can populate it | |
| data_dir = BASE_DIR / "data" | |
| data_dir.mkdir(exist_ok=True) | |
| app.mount("/data", StaticFiles(directory=str(data_dir)), name="data") | |
| async def dashboard(request: Request): | |
| """Serve the main dashboard page""" | |
| return templates.TemplateResponse("dashboard.html", {"request": request}) | |
| async def api_refresh(): | |
| """ | |
| Refresh data from OpenRouter provider pages. | |
| Fetches chart data from all configured providers and saves to data/. | |
| """ | |
| loop = asyncio.get_event_loop() | |
| data = await loop.run_in_executor(None, refresh_data, data_dir) | |
| return { | |
| "status": "ok", | |
| "fetched_at": data["fetched_at"], | |
| "summary": data["summary"], | |
| } | |
| async def health(): | |
| """Health check endpoint""" | |
| return {"status": "ok"} | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run(app, host="0.0.0.0", port=7860) | |