Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from transformers import LayoutLMv3Processor, AutoModel
3
+
4
+ # Step 1: Create the cache directory
5
+ cache_directory = os.path.expanduser('~/huggingface_cache') # Change path as needed
6
+ os.makedirs(cache_directory, exist_ok=True)
7
+
8
+ # Step 2: Set the HF_HOME environment variable
9
+ os.environ['HF_HOME'] = cache_directory
10
+
11
+ # Step 3: Load the processor and model from Hugging Face
12
+ try:
13
+ # Load the LayoutLMv3 processor
14
+ processor = LayoutLMv3Processor.from_pretrained("HURIDOCS/pdf-document-layout-analysis")
15
+
16
+ # Load the model
17
+ model = AutoModel.from_pretrained("HURIDOCS/pdf-document-layout-analysis")
18
+
19
+ print("Model and processor loaded successfully.")
20
+ except Exception as e:
21
+ print(f"An error occurred: {e}")