ysharma HF Staff commited on
Commit
e7e3468
Β·
verified Β·
1 Parent(s): e3c0874

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -6,7 +6,7 @@ for detecting and visualizing PII in PDF/DOC/DOCX documents.
6
 
7
  - Backend: gr.Server (Gradio + FastAPI)
8
  - Frontend: Custom HTML/CSS/JS
9
- - Model: openai/openai-privacy-filter (1.5B params, 50M active, 128k context)
10
  """
11
 
12
  import os
@@ -21,7 +21,8 @@ from fastapi import UploadFile, File
21
  from fastapi.responses import HTMLResponse, JSONResponse
22
 
23
  # ── Configuration ────────────────────────────────────────────────
24
- MODEL_ID = os.getenv("MODEL_ID", "charles-first-org/second-model") #"openai/openai-privacy-filter")
 
25
 
26
  CATEGORIES = {
27
  "private_person": {"color": "#ef4444", "bg": "rgba(239,68,68,0.15)", "label": "Person"},
@@ -40,9 +41,10 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
40
 
41
  from transformers import AutoTokenizer, AutoModelForTokenClassification # noqa: E402
42
 
43
- tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
44
  model = AutoModelForTokenClassification.from_pretrained(
45
- MODEL_ID, trust_remote_code=True, torch_dtype=torch.float16 if device.type == "cuda" else torch.float32
 
46
  )
47
  model.eval().to(device)
48
 
 
6
 
7
  - Backend: gr.Server (Gradio + FastAPI)
8
  - Frontend: Custom HTML/CSS/JS
9
+ - Model: charles-first-org/second-model (1.5B params, 50M active, 128k context)
10
  """
11
 
12
  import os
 
21
  from fastapi.responses import HTMLResponse, JSONResponse
22
 
23
  # ── Configuration ────────────────────────────────────────────────
24
+ MODEL_ID = os.getenv("MODEL_ID", "charles-first-org/second-model")
25
+ HF_TOKEN = os.getenv("HF_TOKEN", None)
26
 
27
  CATEGORIES = {
28
  "private_person": {"color": "#ef4444", "bg": "rgba(239,68,68,0.15)", "label": "Person"},
 
41
 
42
  from transformers import AutoTokenizer, AutoModelForTokenClassification # noqa: E402
43
 
44
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True, token=HF_TOKEN)
45
  model = AutoModelForTokenClassification.from_pretrained(
46
+ MODEL_ID, trust_remote_code=True, token=HF_TOKEN,
47
+ torch_dtype=torch.bfloat16 if device.type == "cuda" else torch.float32,
48
  )
49
  model.eval().to(device)
50