oddadmix commited on
Commit
fc144fa
·
verified ·
1 Parent(s): 85e5e27

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -14,16 +14,20 @@ from fastapi.staticfiles import StaticFiles
14
  from pydantic import BaseModel
15
  from transformers import AutoTokenizer
16
 
17
- from routing_model import MAX_ROUTES, RouterModel, build_text, route
18
 
19
  HF_TOKEN = os.environ.get("MODEL_HF_TOKEN") or os.environ.get("HF_TOKEN")
20
 
21
- # Two backbones on the same head and the same task. The 6M is a bidirectional
22
- # BERT encoder; the 52M is a Llama decoder. Measured on the same eval sets in one
23
- # session, the encoder wins three of four - see the model cards.
24
  REGISTRY = {
25
- "52M": {"repo": "oddadmix/Nawah-Router-v3", "label": "Nawah-Router-v3 (Llama decoder)"},
26
- "6M-BERT": {"repo": "oddadmix/Nawah-Router-BERT-6M-v2", "label": "Nawah-Router-BERT-6M-v2 (BERT encoder)"},
 
 
 
 
27
  }
28
  DEFAULT = os.environ.get("MODEL_KEY", "6M-BERT")
29
 
@@ -79,7 +83,7 @@ def api_route(req: RouteReq):
79
  # returned in the caller's order so the UI does not reshuffle rows under the cursor
80
  "results": [{"route": c, "score": order.get(c, 0.0)} for c in cats],
81
  "top": max(range(len(cats)), key=lambda i: order.get(cats[i], 0.0)),
82
- "ms": round((time.perf_counter() - t0) * 1000), "tokens": ntok,
83
  "model": sel["label"], "params": sel["params"]})
84
 
85
 
 
14
  from pydantic import BaseModel
15
  from transformers import AutoTokenizer
16
 
17
+ from routing_model import MAX_ROUTES, RouterModel, build_text, detect_lang, route
18
 
19
  HF_TOKEN = os.environ.get("MODEL_HF_TOKEN") or os.environ.get("HF_TOKEN")
20
 
21
+ # Three backbones on the same head and the same task. The two 6M's are bidirectional BERT
22
+ # encoders (one Arabic-only, one pretrained jointly on Arabic+English); the 52M is a Llama
23
+ # decoder. Measured on the same eval sets in one session each - see the model cards.
24
  REGISTRY = {
25
+ "52M": {"repo": "oddadmix/Nawah-Router-v3",
26
+ "label": "Nawah-Router-v3 (Llama decoder, Arabic)"},
27
+ "6M-BERT": {"repo": "oddadmix/Nawah-Router-BERT-6M-v2",
28
+ "label": "Nawah-Router-BERT-6M-v2 (BERT encoder, Arabic)"},
29
+ "6M-BILINGUAL": {"repo": "oddadmix/Nawah-Router-BERT-6M-bilingual-pretrained",
30
+ "label": "Nawah-Router-BERT-6M-bilingual-pretrained (BERT encoder, English+Arabic)"},
31
  }
32
  DEFAULT = os.environ.get("MODEL_KEY", "6M-BERT")
33
 
 
83
  # returned in the caller's order so the UI does not reshuffle rows under the cursor
84
  "results": [{"route": c, "score": order.get(c, 0.0)} for c in cats],
85
  "top": max(range(len(cats)), key=lambda i: order.get(cats[i], 0.0)),
86
+ "ms": round((time.perf_counter() - t0) * 1000), "tokens": ntok, "lang": detect_lang(text),
87
  "model": sel["label"], "params": sel["params"]})
88
 
89