m7n commited on
Commit
2887a58
·
1 Parent(s): dbd8935

Refactor spaces import handling in app.py to conditionally import and provide a fallback for non-Space environments.

Browse files
Files changed (1) hide show
  1. app.py +22 -6
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import spaces #
2
  import time
3
  print(f"Starting up: {time.strftime('%Y-%m-%d %H:%M:%S')}")
4
  # source openalex_env_map/bin/activate
@@ -88,11 +88,27 @@ is_running_in_hf_zero_gpu()
88
  def is_running_in_hf_space():
89
  return "SPACE_ID" in os.environ
90
 
91
- #if is_running_in_hf_space():
92
- from spaces.zero.client import _get_token
93
-
94
-
95
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
 
98
  #if is_running_in_hf_space():
 
1
+ #import spaces #
2
  import time
3
  print(f"Starting up: {time.strftime('%Y-%m-%d %H:%M:%S')}")
4
  # source openalex_env_map/bin/activate
 
88
  def is_running_in_hf_space():
89
  return "SPACE_ID" in os.environ
90
 
91
+ # #if is_running_in_hf_space():
92
+ # from spaces.zero.client import _get_token
93
+
94
+
95
+ try:
96
+ import spaces
97
+ from spaces.zero.client import _get_token
98
+ HAS_SPACES = True
99
+ except (ImportError, ModuleNotFoundError):
100
+ HAS_SPACES = False
101
+
102
+ # Provide a harmless fallback so decorators don’t explode
103
+ if not HAS_SPACES:
104
+ class _Dummy:
105
+ def GPU(self, *a, **k):
106
+ def deco(f): # no-op decorator
107
+ return f
108
+ return deco
109
+ spaces = _Dummy() # fake module object
110
+ def _get_token(request): # stub, never called off-Space
111
+ return ""
112
 
113
 
114
  #if is_running_in_hf_space():