Siddharth Ravikumar commited on
Commit
dd6df30
·
1 Parent(s): 47ed39d

Fix ZeroGPU by manually triggering startup_report during FastAPI startup

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -892,6 +892,28 @@ app = gr.mount_gradio_app(
892
  async def startup_event():
893
  logger.info("Starting up FastAPI application...")
894
  await _ensure_init()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
895
 
896
  if __name__ == "__main__":
897
  import uvicorn
 
892
  async def startup_event():
893
  logger.info("Starting up FastAPI application...")
894
  await _ensure_init()
895
+
896
+ # --- Hugging Face ZeroGPU Fix ---
897
+ # When using gr.mount_gradio_app with a custom FastAPI app, gr.Blocks.launch()
898
+ # is bypassed. The `spaces` library hooks `.launch()` to emit the `startup_report`
899
+ # required by ZeroGPU orchestrator to verify `@spaces.GPU` functions exist.
900
+ # Without this report, the Hub errors out with "No @spaces.GPU function detected".
901
+ # Therefore, we manually trigger it here.
902
+ try:
903
+ from spaces import config
904
+ if getattr(config.Config, "zero_gpu", False):
905
+ import spaces.zero as zero
906
+ if hasattr(zero, "startup"):
907
+ zero.startup()
908
+ logger.info("Triggered ZeroGPU startup successfully.")
909
+ elif hasattr(zero, "client"):
910
+ zero.torch.pack()
911
+ zero.client.startup_report()
912
+ logger.info("Triggered ZeroGPU client startup manually.")
913
+ except ImportError:
914
+ pass
915
+ except Exception as e:
916
+ logger.warning(f"Failed to manually trigger ZeroGPU startup report: {e}")
917
 
918
  if __name__ == "__main__":
919
  import uvicorn