avinashHuggingface108 commited on
Commit
fbfadd2
·
1 Parent(s): 3dbdc96

Comprehensive fix for HuggingFace cache directory permissions

Browse files

- Add cache directory environment variables to smolvlm2_handler.py
- Ensure cache directories are set before any transformers import
- Fix model download permission errors at the source
- Prevent PermissionError when downloading SmolVLM2 models

.DS_Store ADDED
Binary file (6.15 kB). View file
 
src/__pycache__/smolvlm2_handler.cpython-313.pyc ADDED
Binary file (11.5 kB). View file
 
src/smolvlm2_handler.py CHANGED
@@ -4,6 +4,17 @@ SmolVLM2 Model Handler
4
  Handles loading and inference with SmolVLM2-1.7B-Instruct model
5
  """
6
 
 
 
 
 
 
 
 
 
 
 
 
7
  import torch
8
  from transformers import AutoModelForImageTextToText, AutoProcessor
9
  from PIL import Image
 
4
  Handles loading and inference with SmolVLM2-1.7B-Instruct model
5
  """
6
 
7
+ import os
8
+ import tempfile
9
+
10
+ # Set cache directories to writable locations before importing transformers
11
+ if 'HF_HOME' not in os.environ:
12
+ CACHE_DIR = tempfile.mkdtemp(prefix="hf_cache_")
13
+ os.environ['HF_HOME'] = CACHE_DIR
14
+ os.environ['TRANSFORMERS_CACHE'] = CACHE_DIR
15
+ os.environ['HF_DATASETS_CACHE'] = CACHE_DIR
16
+ os.environ['TORCH_HOME'] = CACHE_DIR
17
+
18
  import torch
19
  from transformers import AutoModelForImageTextToText, AutoProcessor
20
  from PIL import Image