DevangMahesh commited on
Commit
1db6059
·
1 Parent(s): 4b7bf52

Fixes to machine status check code

Browse files
Files changed (1) hide show
  1. app.py +2 -3
app.py CHANGED
@@ -32,11 +32,12 @@ TIMESTAMP_LAST_CALL_TO_HOPE = None
32
  ONGOING_CONVO = {}
33
 
34
  def is_space_sleeping():
 
35
  headers = {"Authorization": f"Bearer {HF_READ_TKN}"}
36
  response = requests.get("https://huggingface.co/api/spaces/HopeLLM/HopeV1.0", headers=headers)
37
  if response.status_code == 200:
38
  space_info = response.json()
39
- return space_info.get("runtime", {}).get("stage", "") == "sleeping"
40
  return "unknown" # If API call fails, assume the space is sleeping
41
 
42
  def call_hope_api(input_txt, sender_id):
@@ -44,8 +45,6 @@ def call_hope_api(input_txt, sender_id):
44
  global TIMESTAMP_LAST_CALL_TO_HOPE
45
 
46
  TIMESTAMP_LAST_CALL_TO_HOPE = time.time()
47
- sleeping = is_space_sleeping()
48
- logger.info(f"The space is sleeping gave out {sleeping}")
49
  with Lock:
50
  if hope_client == None:
51
  if(is_space_sleeping()==True):
 
32
  ONGOING_CONVO = {}
33
 
34
  def is_space_sleeping():
35
+ # Stage can be SLEEPING, PAUSED, RUNNING, or APP_STARTING
36
  headers = {"Authorization": f"Bearer {HF_READ_TKN}"}
37
  response = requests.get("https://huggingface.co/api/spaces/HopeLLM/HopeV1.0", headers=headers)
38
  if response.status_code == 200:
39
  space_info = response.json()
40
+ return space_info.get("runtime", {}).get("stage", "") == "SLEEPING" or space_info.get("runtime", {}).get("stage", "") == "APP_STARTING"
41
  return "unknown" # If API call fails, assume the space is sleeping
42
 
43
  def call_hope_api(input_txt, sender_id):
 
45
  global TIMESTAMP_LAST_CALL_TO_HOPE
46
 
47
  TIMESTAMP_LAST_CALL_TO_HOPE = time.time()
 
 
48
  with Lock:
49
  if hope_client == None:
50
  if(is_space_sleeping()==True):