Wauplin HF staff commited on
Commit
3855dd6
1 Parent(s): aab7e97

fix recursion

Browse files
Files changed (1) hide show
  1. src/gradio_space_ci/webhook.py +9 -4
src/gradio_space_ci/webhook.py CHANGED
@@ -83,9 +83,11 @@ def enable_space_ci() -> None:
83
  config = card.data.get("space_ci", {})
84
  print(f"Enabling Space CI with config from README: {config}")
85
 
 
 
86
  @wraps(gr.Blocks.launch)
87
- def _launch(self: gr.Blocks, *args, **kwargs) -> None:
88
- configure_space_ci(
89
  blocks=self,
90
  trusted_authors=config.get("trusted_authors"),
91
  private=config.get("private", "auto"),
@@ -93,10 +95,13 @@ def enable_space_ci() -> None:
93
  secrets=config.get("secrets"),
94
  hardware=config.get("hardware"),
95
  storage=config.get("storage"),
96
- ).launch(*args, *kwargs)
 
 
 
97
 
98
  # Monkey patch gradio
99
- gr.Blocks.launch = _launch
100
 
101
 
102
  def configure_space_ci(
 
83
  config = card.data.get("space_ci", {})
84
  print(f"Enabling Space CI with config from README: {config}")
85
 
86
+ old_launch = gr.Blocks.launch
87
+
88
  @wraps(gr.Blocks.launch)
89
+ def new_launch(self: gr.Blocks, *args, **kwargs) -> None:
90
+ server = configure_space_ci(
91
  blocks=self,
92
  trusted_authors=config.get("trusted_authors"),
93
  private=config.get("private", "auto"),
 
95
  secrets=config.get("secrets"),
96
  hardware=config.get("hardware"),
97
  storage=config.get("storage"),
98
+ )
99
+ # De-monkey patch gradio (otherwise it will be called recursively)
100
+ gr.Blocks.launch = old_launch
101
+ server.launch(*args, *kwargs)
102
 
103
  # Monkey patch gradio
104
+ gr.Blocks.launch = new_launch
105
 
106
 
107
  def configure_space_ci(