import os from transformers import LayoutLMv3Processor, AutoModel # Step 1: Create the cache directory cache_directory = os.path.expanduser('~/huggingface_cache') # Change path as needed os.makedirs(cache_directory, exist_ok=True) # Step 2: Set the HF_HOME environment variable os.environ['HF_HOME'] = cache_directory # Step 3: Load the processor and model from Hugging Face try: # Load the LayoutLMv3 processor processor = LayoutLMv3Processor.from_pretrained("HURIDOCS/pdf-document-layout-analysis") # Load the model model = AutoModel.from_pretrained("HURIDOCS/pdf-document-layout-analysis") print("Model and processor loaded successfully.") except Exception as e: print(f"An error occurred: {e}")