Spaces:
Runtime error
Runtime error
Oscar Wang
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
import time
|
3 |
-
from threading import Thread
|
4 |
from gradio_client import Client
|
5 |
from tenacity import retry, stop_after_attempt, wait_fixed, retry_if_exception_type
|
6 |
import httpx
|
@@ -18,6 +18,8 @@ state = {
|
|
18 |
"total_growth_speed": 0
|
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):
|
23 |
result = client.predict(api_name="/update_token_display")
|
@@ -29,21 +31,25 @@ def monitor_growth():
|
|
29 |
curr_count1 = get_token_count(client1)
|
30 |
curr_count2 = get_token_count(client2)
|
31 |
curr_count3 = get_token_count(client3)
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
45 |
except httpx.ReadTimeout:
|
46 |
print("Timeout occurred while fetching token count.")
|
|
|
|
|
47 |
|
48 |
# Start the monitor thread
|
49 |
Thread(target=monitor_growth, daemon=True).start()
|
@@ -56,8 +62,9 @@ growth_speed_placeholder = st.empty()
|
|
56 |
|
57 |
def update_ui():
|
58 |
while True:
|
59 |
-
|
60 |
-
|
|
|
61 |
time.sleep(1)
|
62 |
|
63 |
Thread(target=update_ui, daemon=True).start()
|
|
|
1 |
import streamlit as st
|
2 |
import time
|
3 |
+
from threading import Thread, Lock
|
4 |
from gradio_client import Client
|
5 |
from tenacity import retry, stop_after_attempt, wait_fixed, retry_if_exception_type
|
6 |
import httpx
|
|
|
18 |
"total_growth_speed": 0
|
19 |
}
|
20 |
|
21 |
+
state_lock = Lock()
|
22 |
+
|
23 |
@retry(stop=stop_after_attempt(3), wait=wait_fixed(2), retry=retry_if_exception_type(httpx.ReadTimeout))
|
24 |
def get_token_count(client):
|
25 |
result = client.predict(api_name="/update_token_display")
|
|
|
31 |
curr_count1 = get_token_count(client1)
|
32 |
curr_count2 = get_token_count(client2)
|
33 |
curr_count3 = get_token_count(client3)
|
34 |
+
|
35 |
+
with state_lock:
|
36 |
+
growth_speed1 = curr_count1 - state["prev_count1"]
|
37 |
+
growth_speed2 = curr_count2 - state["prev_count2"]
|
38 |
+
growth_speed3 = curr_count3 - state["prev_count3"]
|
39 |
+
total_tokens = curr_count1 + curr_count2 + curr_count3
|
40 |
+
total_growth_speed = growth_speed1 + growth_speed2 + growth_speed3
|
41 |
+
|
42 |
+
state["prev_count1"] = curr_count1
|
43 |
+
state["prev_count2"] = curr_count2
|
44 |
+
state["prev_count3"] = curr_count3
|
45 |
+
state["prev_total_tokens"] = total_tokens
|
46 |
+
state["total_growth_speed"] = total_growth_speed
|
47 |
+
|
48 |
+
time.sleep(5) # Increased sleep duration
|
49 |
except httpx.ReadTimeout:
|
50 |
print("Timeout occurred while fetching token count.")
|
51 |
+
except Exception as e:
|
52 |
+
print(f"An error occurred: {e}")
|
53 |
|
54 |
# Start the monitor thread
|
55 |
Thread(target=monitor_growth, daemon=True).start()
|
|
|
62 |
|
63 |
def update_ui():
|
64 |
while True:
|
65 |
+
with state_lock:
|
66 |
+
token_count_placeholder.metric("Total Token Count", state["prev_total_tokens"])
|
67 |
+
growth_speed_placeholder.metric("Total Growth Speed", state["total_growth_speed"])
|
68 |
time.sleep(1)
|
69 |
|
70 |
Thread(target=update_ui, daemon=True).start()
|