Peter Michael Gits Claude commited on
Commit
491418e
·
1 Parent(s): 9909d49

fix: Ensure @spaces.GPU function detection at module level

Browse files

- Move GPU/CPU function calls to module level for early detection
- Ensures Hugging Face Spaces detects @spaces.GPU during startup
- Fixes "no @spaces.GPU function detected during startup" error

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -102,6 +102,10 @@ def _dummy_cpu_function():
102
  """Dummy function to satisfy Spaces CPU detection"""
103
  return "CPU available"
104
 
 
 
 
 
105
  import asyncio
106
  import threading
107
  import json
@@ -1021,10 +1025,8 @@ with gr.Blocks(
1021
  def safe_main():
1022
  """Main function with comprehensive error handling and stream protection"""
1023
  try:
1024
- # Initialize Spaces functions for startup detection
1025
- gpu_status = _dummy_gpu_function()
1026
- cpu_status = _dummy_cpu_function()
1027
- print(f"[TTS-INFO] {gpu_status}, {cpu_status}", flush=True)
1028
 
1029
  # === FINAL SAFETY MEASURES ===
1030
  # Last-chance protection against any remaining stream conflicts
 
102
  """Dummy function to satisfy Spaces CPU detection"""
103
  return "CPU available"
104
 
105
+ # Initialize functions at module level for Spaces detection
106
+ _gpu_init = _dummy_gpu_function()
107
+ _cpu_init = _dummy_cpu_function()
108
+
109
  import asyncio
110
  import threading
111
  import json
 
1025
  def safe_main():
1026
  """Main function with comprehensive error handling and stream protection"""
1027
  try:
1028
+ # Spaces functions already initialized at module level
1029
+ print(f"[TTS-INFO] {_gpu_init}, {_cpu_init}", flush=True)
 
 
1030
 
1031
  # === FINAL SAFETY MEASURES ===
1032
  # Last-chance protection against any remaining stream conflicts