"""Minimal inference snippet for jc-builds/polymarket-edge-bot. Install: pip install lightgbm scikit-learn sentence-transformers numpy """ import json import pickle import numpy as np import lightgbm as lgb from sklearn.isotonic import IsotonicRegression from sentence_transformers import SentenceTransformer from huggingface_hub import hf_hub_download REPO = "jc-builds/polymarket-edge-bot" # --- load artifacts --- spec = json.loads(open(hf_hub_download(REPO, "feature_spec.json")).read()) gbm = lgb.Booster(model_file=hf_hub_download(REPO, "lightgbm_model.txt")) iso = pickle.load(open(hf_hub_download(REPO, "isotonic_calibrator.pkl"), "rb")) encoder = SentenceTransformer(spec["embedding_model"]) # --- build a tabular row matching feature_spec.json --- # In production, derive these from the live Polymarket Gamma API payload. tabular_row = {col: 0.0 for col in spec["tabular_columns_in_order"]} tabular_row["first_yes_price"] = 0.30 # current YES price tabular_row["first_yes_price_log_odds"] = float(np.log(0.30 / 0.70)) tabular_row["first_yes_price_distance_from_half"] = 0.20 tabular_row["log_total_usd"] = float(np.log1p(50_000)) tabular_row["duration_days"] = 7 # Question embedding question = "Will Bitcoin close above $100,000 on Friday?" emb = encoder.encode([question], normalize_embeddings=True)[0] # Concatenate x = np.concatenate([ np.array([tabular_row[c] for c in spec["tabular_columns_in_order"]], dtype=np.float32), emb, ])[None, :] # --- score --- p_raw = gbm.predict(x)[0] p_yes = float(iso.predict([p_raw])[0]) edge = p_yes - tabular_row["first_yes_price"] print(f"P(YES) = {p_yes:.3f} market = {tabular_row['first_yes_price']:.3f} " f"edge = {edge:+.3f} {'BUY YES' if edge > 0.05 else 'BUY NO' if edge < -0.05 else 'skip'}")