shukdev3 commited on
Commit
8ca0d25
·
verified ·
1 Parent(s): d61bcf0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py CHANGED
@@ -11,6 +11,29 @@ import sys
11
  import platform
12
  from collections import defaultdict
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  # Available English voices for different providers
15
  groq_voices = [
16
  "Arista-PlayAI", "Atlas-PlayAI", "Basil-PlayAI", "Briggs-PlayAI",
 
11
  import platform
12
  from collections import defaultdict
13
 
14
+ # Hugging Face Spaces ZeroGPU compatibility.
15
+ # If a Space's hardware is set to "ZeroGPU", HF requires at least one
16
+ # function decorated with @spaces.GPU to be registered at startup, or it
17
+ # fails with: "No @spaces.GPU function detected during startup".
18
+ # This app does no GPU work at all (pure OpenCV/CPU), so the decorator
19
+ # below is a no-op wrapper everywhere except on a ZeroGPU Space, where it
20
+ # satisfies that startup requirement. If you don't need ZeroGPU hardware,
21
+ # the simpler fix is to switch the Space's hardware to "CPU basic" instead.
22
+ try:
23
+ import spaces
24
+ HAS_SPACES = True
25
+ except ImportError:
26
+ spaces = None
27
+ HAS_SPACES = False
28
+
29
+
30
+ def gpu_compatible(fn):
31
+ """Wrap fn with @spaces.GPU when running on a HF ZeroGPU Space;
32
+ otherwise return fn unchanged so local/non-Spaces runs are unaffected."""
33
+ if HAS_SPACES:
34
+ return spaces.GPU(fn)
35
+ return fn
36
+
37
  # Available English voices for different providers
38
  groq_voices = [
39
  "Arista-PlayAI", "Atlas-PlayAI", "Basil-PlayAI", "Briggs-PlayAI",