Spaces:
Configuration error
Configuration error
Download src/hf_mcp_server.py from Brettapps/Trifecta-Lab: direct link, hf CLI and curl.
- Browser
- Download file 1.88 kB
-
https://huggingface.co/spaces/Brettapps/Trifecta-Lab/resolve/main/src/hf_mcp_server.py
- Command line
-
hf download hf://spaces/Brettapps/Trifecta-Lab/src/hf_mcp_server.py
-
curl -L -o hf_mcp_server.py https://huggingface.co/spaces/Brettapps/Trifecta-Lab/resolve/main/src/hf_mcp_server.py
1.88 kB
| """HF Space MCP server for Trifecta Pro predictions.""" | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| from typing import Any | |
| from .prediction_model import Race, Runner, TrifectaPredictor | |
| def load_predictions(date: str) -> dict[str, Any]: | |
| path = Path(__file__).resolve().parents[1] / "data" / "predictions" / f"predictions-{date}.json" | |
| if not path.exists(): | |
| return {"error": f"No predictions for {date}", "path": str(path)} | |
| return json.loads(path.read_text()) | |
| def list_pdfs() -> dict[str, Any]: | |
| pdf_dir = Path(__file__).resolve().parents[1] / "data" / "pdfs" | |
| pdfs = sorted([p.name for p in pdf_dir.glob("*.pdf")]) if pdf_dir.exists() else [] | |
| return {"pdfs": pdfs} | |
| class HFMCPServer: | |
| def __init__(self, space_name: str = "Brettapps/trifecta-bro", access_token: str | None = None) -> None: | |
| self.space_name = space_name | |
| self.access_token = access_token | |
| self.predictor = TrifectaPredictor() | |
| def get_latest_predictions(self, date: str | None = None) -> dict[str, Any]: | |
| if not date: | |
| from datetime import date as d, timedelta | |
| date = (d.today() + timedelta(days=1)).isoformat() | |
| return load_predictions(date) | |
| def get_pdf_list(self) -> dict[str, Any]: | |
| return list_pdfs() | |
| def download_pdf(self, pdf_name: str) -> dict[str, Any]: | |
| pdf_dir = Path(__file__).resolve().parents[1] / "data" / "pdfs" | |
| path = pdf_dir / pdf_name | |
| if not path.exists(): | |
| return {"error": f"PDF not found: {pdf_name}"} | |
| return {"path": str(path), "name": pdf_name} | |
| def get_space_status(self) -> dict[str, Any]: | |
| return { | |
| "space": self.space_name, | |
| "status": "ok", | |
| "predictor": "trifecta-model-v1", | |
| } | |
| def create_mcp_server() -> HFMCPServer: | |
| return HFMCPServer() | |