File size: 593 Bytes
68964c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os
from huggingface_hub import login
from transformers import pipeline

hf_token = os.getenv('HF_TOKEN')
if hf_token:
    login(token=hf_token)

cache_dir = '/app/hf_cache'
model_name = 'dslim/distilbert-NER'

expected_cache_path = os.path.join(cache_dir, 'transformers', model_name.replace('/', '--'))

if not os.path.exists(expected_cache_path):
    print(f'Downloading NER model: {model_name}...')
    nlp = pipeline('token-classification', model=model_name)
else:
    print(f'NER model ({model_name}) already cached. Skipping download.')

print('NER model download check complete.')