Oscar Wang commited on
Commit
3421757
·
verified ·
1 Parent(s): 0f28c01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -19,16 +19,18 @@ state = {
19
  }
20
 
21
  @retry(stop=stop_after_attempt(3), wait=wait_fixed(2), retry=retry_if_exception_type(httpx.ReadTimeout))
22
- def get_token_count():
23
- result1 = client1.predict(api_name="/update_token_display", timeout=10.0)
24
- result2 = client2.predict(api_name="/update_token_display", timeout=10.0)
25
- result3 = client3.predict(api_name="/update_token_display", timeout=10.0)
26
- return int(result1), int(result2), int(result3)
27
 
28
  def monitor_growth():
29
  while True:
30
  try:
31
- curr_count1, curr_count2, curr_count3 = get_token_count()
 
 
32
  growth_speed1 = curr_count1 - state["prev_count1"]
33
  growth_speed2 = curr_count2 - state["prev_count2"]
34
  growth_speed3 = curr_count3 - state["prev_count3"]
 
19
  }
20
 
21
  @retry(stop=stop_after_attempt(3), wait=wait_fixed(2), retry=retry_if_exception_type(httpx.ReadTimeout))
22
+ def get_token_count(client, api_name):
23
+ url = f"{client.base_url}{api_name}"
24
+ response = httpx.get(url, timeout=10.0)
25
+ response.raise_for_status() # Raise an exception for HTTP errors
26
+ return int(response.json())
27
 
28
  def monitor_growth():
29
  while True:
30
  try:
31
+ curr_count1 = get_token_count(client1, "/update_token_display")
32
+ curr_count2 = get_token_count(client2, "/update_token_display")
33
+ curr_count3 = get_token_count(client3, "/update_token_display")
34
  growth_speed1 = curr_count1 - state["prev_count1"]
35
  growth_speed2 = curr_count2 - state["prev_count2"]
36
  growth_speed3 = curr_count3 - state["prev_count3"]