CodCodingCode commited on
Commit
65aa5a5
Β·
1 Parent(s): d0e445c

Use snapshot_download+allow_patterns without subfolder arg

Browse files
Files changed (2) hide show
  1. app.py +11 -14
  2. requirements.txt +1 -1
app.py CHANGED
@@ -4,24 +4,22 @@ from huggingface_hub import snapshot_download
4
  from transformers import AutoTokenizer, AutoModelForCausalLM
5
  import gradio as gr
6
 
7
- # β€”β€”β€” CONFIG β€”β€”β€”
8
- REPO_ID = "CodCodingCode/llama-3.1-8b-clinical"
9
- SUBFOLDER = "checkpoint-45000"
10
- HF_TOKEN = os.environ["HUGGINGFACE_HUB_TOKEN"] # set in Settings→Secrets
11
-
12
- # β€”β€”β€” SNAPSHOT & LOAD β€”β€”β€”
13
- # This will grab all .json and .safetensors under checkpoint-45000:
14
- local_dir = snapshot_download(
15
  repo_id=REPO_ID,
16
- subfolder=SUBFOLDER,
17
  token=HF_TOKEN,
18
- allow_patterns=["*.json", "*.safetensors"],
19
  )
20
 
21
- # Now point at that folder:
22
- MODEL_DIR = local_dir # e.g. ~/.cache/huggingface/…/checkpoint-45000
23
 
24
- # Load tokenizer & model from the real files you just pulled:
25
  tokenizer = AutoTokenizer.from_pretrained(
26
  MODEL_DIR,
27
  use_fast=False,
@@ -36,7 +34,6 @@ model = AutoModelForCausalLM.from_pretrained(
36
  model.eval()
37
 
38
 
39
-
40
  # === Role Agent with instruction/input/output format ===
41
  class RoleAgent:
42
  def __init__(self, role_instruction):
 
4
  from transformers import AutoTokenizer, AutoModelForCausalLM
5
  import gradio as gr
6
 
7
+ # β€”β€”β€” CONFIG β€”β€”β€”
8
+ REPO_ID = "CodCodingCode/llama-3.1-8b-clinical"
9
+ SUBFOLDER = "checkpoint-45000"
10
+ HF_TOKEN = os.getenv("HUGGINGFACE_HUB_TOKEN")
11
+
12
+ # β€”β€”β€” DOWNLOAD ONLY THE CHECKPOINT FILES β€”β€”β€”
13
+ local_cache = snapshot_download(
 
14
  repo_id=REPO_ID,
 
15
  token=HF_TOKEN,
16
+ allow_patterns=[f"{SUBFOLDER}/*.json", f"{SUBFOLDER}/*.safetensors"],
17
  )
18
 
19
+ # β€”β€”β€” POINT AT THE REAL FILES β€”β€”β€”
20
+ MODEL_DIR = os.path.join(local_cache, SUBFOLDER)
21
 
22
+ # β€”β€”β€” LOAD MODEL & TOKENIZER β€”β€”β€”
23
  tokenizer = AutoTokenizer.from_pretrained(
24
  MODEL_DIR,
25
  use_fast=False,
 
34
  model.eval()
35
 
36
 
 
37
  # === Role Agent with instruction/input/output format ===
38
  class RoleAgent:
39
  def __init__(self, role_instruction):
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- huggingface_hub==0.25.2
2
  transformers>=4.38.0
3
  torch>=2.1.0
4
  peft>=0.9.0
 
1
+ huggingface-hub==0.31.4
2
  transformers>=4.38.0
3
  torch>=2.1.0
4
  peft>=0.9.0