Spaces:
Runtime error
Runtime error
Oscar Wang
commited on
Update app.py
Browse files
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 |
-
|
24 |
-
|
25 |
-
|
26 |
-
return int(
|
27 |
|
28 |
def monitor_growth():
|
29 |
while True:
|
30 |
try:
|
31 |
-
curr_count1
|
|
|
|
|
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"]
|