#!/usr/bin/env python3 """ hf_pro/app.py ============= Interactive Web UI & Real-Time Orchestrator for Hugging Face Pro High-Budget Benchmark. Runs on port 7860 (Hugging Face Spaces default). """ import os import sys import time import json import threading import subprocess from fastapi import FastAPI from fastapi.responses import HTMLResponse, JSONResponse import uvicorn app = FastAPI(title="Hyperliquid Microstructure 2x3 Benchmark") # Global execution state state = { "status": "INITIALIZING", "active_model": None, "completed_models": 0, "total_models": 6, "current_trial": 0, "total_trials": 100, "results": [], "logs": [] } def log_msg(msg: str): timestamp = time.strftime("%H:%M:%S") entry = f"[{timestamp}] {msg}" print(entry) state["logs"].append(entry) if len(state["logs"]) > 200: state["logs"].pop(0) def run_high_budget_benchmark(): log_msg("🚀 Hugging Face Pro Benchmark worker initialized.") state["status"] = "RUNNING" # Import execution logic try: import torch has_cuda = torch.cuda.is_available() log_msg(f"Hardware check: CUDA Available = {has_cuda}") if has_cuda: log_msg(f"Active GPU: {torch.cuda.get_device_name(0)}") else: log_msg(f"High-vCPU fallback: {os.cpu_count()} threads available") import run_hf_pro_high_budget as runner # 1. Stream data log_msg("Streaming multi-asset partitions from Hugging Face ProbioticFarmer/hyperliquid-augmented-copytrading...") train_dates = [f"2026-08-{d:02d}" for d in range(15, 31, 2)] + [f"2026-09-{d:02d}" for d in range(1, 14, 2)] test_dates = [f"2026-09-{d:02d}" for d in range(15, 30, 2)] + [f"2026-10-{d:02d}" for d in range(1, 14, 2)] df_tr_raw, df_te_raw = runner.stream_hf_pro_dataset(train_dates, test_dates, max_rows_day=3000) log_msg(f"Streamed {len(df_tr_raw):,} train fills and {len(df_te_raw):,} test fills.") # 2. Features log_msg("Building non-stationary-proof microstructure features (Who, What, Conditions)...") df_train, feat_cols, cat_cols, num_cols = runner.build_features(df_tr_raw) df_test, _, _, _ = runner.build_features(df_te_raw) val_idx = int(len(df_train) * 0.8) X_tr = df_train.iloc[:val_idx][feat_cols] y_tr = df_train.iloc[:val_idx]['target'] X_val = df_train.iloc[val_idx:][feat_cols] y_val = df_train.iloc[val_idx:]['target'] X_te = df_test[feat_cols] y_te = df_test['target'] # 3. CatBoost By-Hand & Optuna state["active_model"] = "CatBoost By-Hand" log_msg("Training CatBoost By-Hand...") # (Runner execution handles models and appends to state['results']) runner.main() if os.path.exists("results_hf_pro_high_budget.json"): with open("results_hf_pro_high_budget.json") as f: state["results"] = json.load(f) state["status"] = "COMPLETED" log_msg("🏆 All 6 matrix configurations successfully evaluated!") except Exception as e: log_msg(f"❌ Execution error: {e}") state["status"] = "ERROR" @app.on_event("startup") def startup_event(): thread = threading.Thread(target=run_high_budget_benchmark, daemon=True) thread.start() @app.get("/api/state") def get_state(): return JSONResponse(state) @app.get("/", response_class=HTMLResponse) def index(): return """
High-Budget Tier (Hugging Face Pro Dedicated Compute) • 2x3 Matrix Evaluation
| Model | Tuning | PR-AUC (Primary) | ROC-AUC | Brier Score | Latency (ms/1k) |
|---|---|---|---|---|---|
| Waiting for first benchmark iteration to complete... | |||||