hsuwill000 commited on
Commit
5e09053
·
verified ·
1 Parent(s): 364152a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -0
app.py CHANGED
@@ -5,9 +5,11 @@ import os
5
  import time
6
  import traceback
7
  import asyncio
 
8
 
9
  # Your Hugging Face API key (ensure this is set in your environment or replace directly)
10
  api_key = os.getenv('MY_API_KEY')
 
11
 
12
  # List of repos (private spaces)
13
  repos = [
@@ -70,6 +72,14 @@ async def infer_gradio(prompt: str):
70
  # Create a list of tasks (one for each repo)
71
  tasks = []
72
  for repo in repos:
 
 
 
 
 
 
 
 
73
  # Create a CustomClient instance for each repo
74
  client = CustomClient(repo, hf_token=api_key, timeout=300)
75
  task = infer_single_gradio(client, prompt)
 
5
  import time
6
  import traceback
7
  import asyncio
8
+ from huggingface_hub import HfApi
9
 
10
  # Your Hugging Face API key (ensure this is set in your environment or replace directly)
11
  api_key = os.getenv('MY_API_KEY')
12
+ api = HfApi(token=api_key)
13
 
14
  # List of repos (private spaces)
15
  repos = [
 
72
  # Create a list of tasks (one for each repo)
73
  tasks = []
74
  for repo in repos:
75
+ runtime_info = api.get_space_runtime(repo)
76
+ if runtime_info.stage == 'SLEEPING':
77
+ print(f"{repo} is now SLEEPING.")
78
+ api.restart_space(repo_id=repo)
79
+ if runtime_info.stage in ['SLEEPING', 'PAUSED']:
80
+ print(f"{repo} is now SLEEPING or PAUSED.")
81
+ api.restart_space(repo_id=repo)
82
+
83
  # Create a CustomClient instance for each repo
84
  client = CustomClient(repo, hf_token=api_key, timeout=300)
85
  task = infer_single_gradio(client, prompt)