hatimanees commited on
Commit
1f56d49
·
verified ·
1 Parent(s): 2882569

Update run.py

Browse files
Files changed (1) hide show
  1. run.py +21 -13
run.py CHANGED
@@ -8,23 +8,31 @@ import re
8
  from werkzeug.utils import secure_filename
9
  import uuid
10
 
 
 
 
 
11
  if platform.system() == "Windows":
12
- print("Windows detected. Assigning cache directory to Transformers in AppData\Local.")
13
  transformers_cache_directory = os.path.join(os.getenv('LOCALAPPDATA'), 'transformers_cache')
14
- if not os.path.exists(transformers_cache_directory):
15
- try:
16
- os.mkdir(transformers_cache_directory)
17
- print(f"First launch. Directory '{transformers_cache_directory}' created successfully.")
18
- except OSError as e:
19
- print(f"Error creating directory '{transformers_cache_directory}': {e}")
20
- else:
21
- print(f"Directory '{transformers_cache_directory}' already exists.")
22
- os.environ['TRANSFORMERS_CACHE'] = transformers_cache_directory
23
- print("Environment variable assigned.")
24
- del transformers_cache_directory
25
 
 
 
 
 
 
 
 
26
  else:
27
- print("Windows not detected. Assignment of Transformers cache directory not necessary.")
 
 
 
 
 
28
 
29
  class Config:
30
  UPLOAD_FOLDER = os.path.join(os.path.dirname(__file__), 'uploads') # Correct path
 
8
  from werkzeug.utils import secure_filename
9
  import uuid
10
 
11
+ import os
12
+ import platform
13
+
14
+ # Set Transformers Cache Directory
15
  if platform.system() == "Windows":
16
+ print("Windows detected. Assigning cache directory to Transformers in AppData\\Local.")
17
  transformers_cache_directory = os.path.join(os.getenv('LOCALAPPDATA'), 'transformers_cache')
18
+ else:
19
+ print("Non-Windows system detected. Assigning cache directory to /tmp/transformers_cache.")
20
+ transformers_cache_directory = '/tmp/transformers_cache'
 
 
 
 
 
 
 
 
21
 
22
+ # Ensure the directory exists
23
+ if not os.path.exists(transformers_cache_directory):
24
+ try:
25
+ os.makedirs(transformers_cache_directory, exist_ok=True)
26
+ print(f"Directory '{transformers_cache_directory}' created successfully.")
27
+ except OSError as e:
28
+ print(f"Error creating directory '{transformers_cache_directory}': {e}")
29
  else:
30
+ print(f"Directory '{transformers_cache_directory}' already exists.")
31
+
32
+ # Set the TRANSFORMERS_CACHE environment variable
33
+ os.environ['TRANSFORMERS_CACHE'] = transformers_cache_directory
34
+ print(f"Environment variable TRANSFORMERS_CACHE set to '{transformers_cache_directory}'.")
35
+
36
 
37
  class Config:
38
  UPLOAD_FOLDER = os.path.join(os.path.dirname(__file__), 'uploads') # Correct path