Matthias Kleiner commited on
Commit
1f0d187
1 Parent(s): 9652e54

added wait and retry if private space needed to be restarted

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py CHANGED
@@ -4,6 +4,7 @@ import os
4
  import random
5
  import datetime
6
  from huggingface_hub import hf_api
 
7
 
8
  def check_password(username, password):
9
  if password == os.environ["ACCESS"]:
@@ -24,6 +25,21 @@ def func(file, number_of_pages, secret):
24
  space_runtime_after_restart = hf_api.restart_space("ByMatthew/deckify_private", token=read_key)
25
  print(f"Space runtime after restart: {space_runtime_after_restart}")
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  client = Client("ByMatthew/deckify_private", hf_token=read_key)
28
 
29
  print(f"Client: {client}")
 
4
  import random
5
  import datetime
6
  from huggingface_hub import hf_api
7
+ import time
8
 
9
  def check_password(username, password):
10
  if password == os.environ["ACCESS"]:
 
25
  space_runtime_after_restart = hf_api.restart_space("ByMatthew/deckify_private", token=read_key)
26
  print(f"Space runtime after restart: {space_runtime_after_restart}")
27
 
28
+
29
+ max_retries = 20
30
+ retry_delay = 10
31
+ success = False
32
+ for i in range(max_retries):
33
+ space_runtime = hf_api.get_space_runtime("ByMatthew/deckify_private", token=read_key)
34
+ print(f"Space runtime: {space_runtime}")
35
+ if space_runtime.stage == "RUNNING":
36
+ success = True
37
+ break
38
+ time.sleep(retry_delay)
39
+
40
+ if not success:
41
+ return "Failed to start the private space in time. Please try again later."
42
+
43
  client = Client("ByMatthew/deckify_private", hf_token=read_key)
44
 
45
  print(f"Client: {client}")