0

I am trying to create an exe using pyinstaller of huggingface model. My code is working without exe, but when i convert it into exe, it did not work. It did not throw any error. It just get finished. Here is the piece of code

bundle_dir = getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__)))
path = os.path.abspath(os.path.join(bundle_dir,"nlpmodels", modelname))
print('dirs',os.listdir(path))
print('model path',path)
tokenizer = AutoTokenizer.from_pretrained(path,local_files_only=True,truncation=True, model_max_length=512)
model = AutoModelForTokenClassification.from_pretrained(path,local_files_only=True)
classifier = pipeline('token-classification', model=model, tokenizer=tokenizer)
print(' classifier',classifier)

here is output print statements

dirs['config.json', 'gitattributes.txt', 'pytorch_model.bin', 'README.md', 'special_tokens_map.json', 'tokenizer_config.json', 'vocab.txt']

model path C:\Users\ADMINI~1\AppData\Local\Temp\2\_MEI25162\nlpmodels\stanford-deidentifier-base

I also print out tokenizer and model and I can see it in exe console. The content of dirs statement is same before and after creating exe. Issue is that my code is not printing classifier statement.

Is there any way to get an idea whats going wrong. May be I can get some sort of error to see why its not working

Talha Anwar
  • 2,699
  • 4
  • 23
  • 62

1 Answers1

0

Make sure that pyinstaller can find the files.

a common issue is the use of relative paths. use this function to adjust the paths:

def get_correct_path(relative_path):
    try:
        base_path = sys._MEIPASS
    except Exception:
        base_path = os.path.abspath(".")

    return os.path.join(base_path, relative_path)

source