Pluggable API Gateway for Hosted Machine Learning Models.

Aggregates standalone Python packages into a single Hugging Face Spaces container. Shared memory warmups, streaming byte guards, zero-downtime fault isolation, and deterministic lockfile rebuilds.

BASE URL https://idkhowtocodefr-hf-backend.hf.space
7860 Hugging Face Port
< 20ms Gateway Overhead
10 MB Body Size Limit
12 hrs Keep-Alive Cadence
Mounted Services

Independent Python packages. Isolated execution.

Each subproject lives in its own repository, tests independently, and registers an APIRouter. Faults in one service do not crash the gateway.

HeartFlow Logo
/heartflow

HeartFlow OS

Active

Clinical cardiovascular risk scoring and interpretability engine. Evaluates vitals, computes local SHAP feature attributions, and compiles TinyML C header artifacts for embedded microcontrollers.

ROC-AUC94.2%
ExplainabilitySHAP Tree
Edge TargetTinyML C99
Key Endpoints
  • POST/heartflow/predictRisk Score + SHAP
  • GET/heartflow/tinyml/exportC Header Generator
  • POST/heartflow/retrainIn-memory Retraining
Semantic Analyzer Logo
/semantic

Semantic Analyzer

Active

Multi-task NLP inference engine for developer and community feedback. Computes dense sentence embeddings, polarity scores, and multi-label toxicity classifications with pre-warmed weights.

EmbeddingMiniLM-L6-v2
ToxicityMulti-label
Latency~18ms CPU
Key Endpoints
  • POST/semantic/analyzeFull NLP Extraction
  • POST/semantic/embed384-dim Dense Vector
  • GET/semantic/healthModel Readiness
Interactive API Explorer

Test mounted routes live

Explore and execute requests across the three mounted gateways. View sample payloads and expected responses, or execute live queries directly against the Hugging Face Space.

HF Backend Core Gateway Central routing, status table, and health telemetry endpoints.
Target: https://idkhowtocodefr-hf-backend.hf.space
Reliability & Design

Built for Hugging Face Spaces constraints

Designed to handle container sleep timeouts, CPU quotas, and multi-model memory warmups without failure cascading.

01

Memory Warmup at Boot

Packages register optional non-blocking warmup routines. Transformer weights and decision trees are loaded into RAM before traffic arrives, avoiding cold-hit timeouts.

02

Streaming Payload Guards

A custom Starlette middleware counts raw stream bytes in chunks. Oversized payloads reject immediately at 10 MB before exhausting container RAM or blocking the event loop.

03

Non-Failing Fault Isolation

If an upstream package raises an import error or fails warmup, the gateway marks overall health as degraded, logs the traceback, and serves remaining subprojects uninterrupted.

04

Deterministic Lockfiles

A 7-day scheduled cron tests upstream git semver releases, compiles verified hashes via uv, and pushes to main to auto-rebuild Hugging Face Spaces.

System Topology

Request Ingress & Subproject Routing Flow

Single Container • Zero Network Hops
HUGGING FACE SPACES CONTAINER (:7860) • LINUX x86_64 • 16 GB SHARED RAM INGRESS CLIENTS Web Frontends GitHub Pages SPA Cross-Origin Fetch Edge Devices ESP32 & Arduino Nodes TinyML Header Sync Automation Crons GitHub Actions 12h Keep-Alive & CI Starlette Gateway Ingress Streaming Byte Guard 10 MB Chunk-Count Limit CORS & Origin Filter github.io & localhost Boot Warmup Sentinel Non-blocking Thread Pool Path Prefix Router Zero-Copy In-Memory Mount / /health, /status /heartflow/* Vitals & TinyML /semantic/* NLP & Embeddings HF Backend Gateway main.py (Root Host) FastAPI Swagger UI & Probes HEARTFLOW_OS heartflow-backend 5 Model Ensamble & SHAP Explainer Semantic Comment Analyze semantic-backend MiniLM-L6-v2 & Toxicity NLP In-Memory Router Mounting • No HTTP Intermediary Direct FastAPI include_router() registration eliminates inter-service serialization latency and network timeouts.
1. Container Packing vs Microservices

Free-tier Hugging Face Spaces sleep after periods of inactivity. Deploying each subproject to an isolated Space multiplies cold starts and introduces 80–120ms of cross-space network latency. Packing standalone Python packages into a single container uses the full 16 GB memory allocation, shares the PyTorch runtime, and routes requests in memory.

2. Prefix-Based Fault Isolation

Subprojects install from git tags into the Python environment and expose independent router instances. The gateway attaches them under explicit path prefixes (/heartflow, /semantic). If an upstream dependency fails during import or warmup, the gateway logs the traceback, reports degraded health, and continues serving the remaining subprojects.

3. Streaming Ingress Guards

Before reaching router handlers, incoming requests pass through Starlette middleware that counts raw stream bytes in chunks. Oversized payloads reject immediately at 10 MB with HTTP 413, preventing unbounded memory allocation from exhausting the container RAM or stalling the event loop.