Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files13 unmodified lines1415161718192021222324252627282949 unmodified lines7980818283848513 unmodified linesfrom pydantic import BaseModelfrom transformers import AutoTokenizerfrom routing_model import MAX_ROUTES, RouterModel, build_text, routeHF_TOKEN = os.environ.get("MODEL_HF_TOKEN") or os.environ.get("HF_TOKEN")# Two backbones on the same head and the same task. The 6M is a bidirectional# BERT encoder; the 52M is a Llama decoder. Measured on the same eval sets in one# session, the encoder wins three of four - see the model cards.REGISTRY = {"52M": {"repo": "oddadmix/Nawah-Router-v3", "label": "Nawah-Router-v3 (Llama decoder)"},"6M-BERT": {"repo": "oddadmix/Nawah-Router-BERT-6M-v2", "label": "Nawah-Router-BERT-6M-v2 (BERT encoder)"},}DEFAULT = os.environ.get("MODEL_KEY", "6M-BERT")49 unmodified lines# returned in the caller's order so the UI does not reshuffle rows under the cursor"results": [{"route": c, "score": order.get(c, 0.0)} for c in cats],"top": max(range(len(cats)), key=lambda i: order.get(cats[i], 0.0)),"ms": round((time.perf_counter() - t0) * 1000), "tokens": ntok,"model": sel["label"], "params": sel["params"]})13 unmodified lines141516171819202122232425262728293031323349 unmodified lines8384858687888913 unmodified linesfrom pydantic import BaseModelfrom transformers import AutoTokenizerfrom routing_model import MAX_ROUTES, RouterModel, build_text, detect_lang, routeHF_TOKEN = os.environ.get("MODEL_HF_TOKEN") or os.environ.get("HF_TOKEN")# Three backbones on the same head and the same task. The two 6M's are bidirectional BERT# encoders (one Arabic-only, one pretrained jointly on Arabic+English); the 52M is a Llama# decoder. Measured on the same eval sets in one session each - see the model cards.REGISTRY = {"52M": {"repo": "oddadmix/Nawah-Router-v3","label": "Nawah-Router-v3 (Llama decoder, Arabic)"},"6M-BERT": {"repo": "oddadmix/Nawah-Router-BERT-6M-v2","label": "Nawah-Router-BERT-6M-v2 (BERT encoder, Arabic)"},"6M-BILINGUAL": {"repo": "oddadmix/Nawah-Router-BERT-6M-bilingual-pretrained","label": "Nawah-Router-BERT-6M-bilingual-pretrained (BERT encoder, English+Arabic)"},}DEFAULT = os.environ.get("MODEL_KEY", "6M-BERT")49 unmodified lines# returned in the caller's order so the UI does not reshuffle rows under the cursor"results": [{"route": c, "score": order.get(c, 0.0)} for c in cats],"top": max(range(len(cats)), key=lambda i: order.get(cats[i], 0.0)),"ms": round((time.perf_counter() - t0) * 1000), "tokens": ntok, "lang": detect_lang(text),"model": sel["label"], "params": sel["params"]})
app.py+11-7