crash10155 commited on
Commit
6ae913c
·
verified ·
1 Parent(s): ee32aca

Update SwitcherAI/utilities.py

Browse files
Files changed (1) hide show
  1. SwitcherAI/utilities.py +19 -1
SwitcherAI/utilities.py CHANGED
@@ -242,4 +242,22 @@ def get_temp_directory_info() -> dict:
242
  'is_hf_spaces': bool(os.getenv('SPACE_ID')),
243
  'temp_exists': os.path.exists(TEMP_DIRECTORY_PATH),
244
  'temp_writable': os.access(TEMP_DIRECTORY_PATH, os.W_OK) if os.path.exists(TEMP_DIRECTORY_PATH) else False
245
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  'is_hf_spaces': bool(os.getenv('SPACE_ID')),
243
  'temp_exists': os.path.exists(TEMP_DIRECTORY_PATH),
244
  'temp_writable': os.access(TEMP_DIRECTORY_PATH, os.W_OK) if os.path.exists(TEMP_DIRECTORY_PATH) else False
245
+ }
246
+ def resolve_relative_path(relative_path: str):
247
+ """Fix for path handling - always return Path objects"""
248
+ from pathlib import Path
249
+ import sys
250
+
251
+ try:
252
+ if hasattr(sys, '_MEIPASS'):
253
+ base_dir = Path(sys._MEIPASS)
254
+ else:
255
+ base_dir = Path(__file__).parent.parent if '__file__' in globals() else Path.cwd()
256
+
257
+ resolved_path = (base_dir / relative_path).resolve()
258
+ resolved_path.parent.mkdir(parents=True, exist_ok=True)
259
+ return resolved_path
260
+ except Exception:
261
+ fallback_path = Path.cwd() / relative_path
262
+ fallback_path.parent.mkdir(parents=True, exist_ok=True)
263
+ return fallback_path