# app.py – FIXED encoder-only demo for bert-beatrix-2048 # launch: python app.py # ----------------------------------------------- import json, re, sys, math from pathlib import Path, PurePosixPath import torch, torch.nn.functional as F import gradio as gr import spaces from huggingface_hub import snapshot_download from bert_handler import create_handler_from_checkpoint # ------------------------------------------------------------------ # 0. Download & patch HF checkpoint -------------------------------- REPO_ID = "AbstractPhil/bert-beatrix-2048" LOCAL_CKPT = "bert-beatrix-2048" snapshot_download( repo_id=REPO_ID, revision="main", local_dir=LOCAL_CKPT, local_dir_use_symlinks=False, ) # → strip repo prefix in auto_map (one-time) cfg_path = Path(LOCAL_CKPT) / "config.json" with cfg_path.open() as f: cfg = json.load(f) amap = cfg.get("auto_map", {}) for k,v in amap.items(): if "--" in v: amap[k] = PurePosixPath(v.split("--",1)[1]).as_posix() cfg["auto_map"] = amap with cfg_path.open("w") as f: json.dump(cfg,f,indent=2) # ------------------------------------------------------------------ # 1. Load model & components -------------------------------------- handler, full_model, tokenizer = create_handler_from_checkpoint(LOCAL_CKPT) full_model = full_model.eval().cuda() # ------------------------------------------------------------------ # 2. Symbolic roles ------------------------------------------------- SYMBOLIC_ROLES = [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "