Spaces:
Runtime error
Runtime error
Oscar Wang
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -19,6 +19,7 @@ state = {
|
|
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):
|
@@ -26,7 +27,7 @@ def get_token_count(client):
|
|
26 |
return int(result)
|
27 |
|
28 |
def monitor_growth():
|
29 |
-
while
|
30 |
try:
|
31 |
curr_count1 = get_token_count(client1)
|
32 |
curr_count2 = get_token_count(client2)
|
@@ -52,7 +53,8 @@ def monitor_growth():
|
|
52 |
print(f"An error occurred: {e}")
|
53 |
|
54 |
# Start the monitor thread
|
55 |
-
Thread(target=monitor_growth, daemon=True)
|
|
|
56 |
|
57 |
# Streamlit UI
|
58 |
st.title("Token Count Dashboard")
|
@@ -61,10 +63,19 @@ token_count_placeholder = st.empty()
|
|
61 |
growth_speed_placeholder = st.empty()
|
62 |
|
63 |
def update_ui():
|
64 |
-
while
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
}
|
20 |
|
21 |
state_lock = Lock()
|
22 |
+
stop_threads = False
|
23 |
|
24 |
@retry(stop=stop_after_attempt(3), wait=wait_fixed(2), retry=retry_if_exception_type(httpx.ReadTimeout))
|
25 |
def get_token_count(client):
|
|
|
27 |
return int(result)
|
28 |
|
29 |
def monitor_growth():
|
30 |
+
while not stop_threads:
|
31 |
try:
|
32 |
curr_count1 = get_token_count(client1)
|
33 |
curr_count2 = get_token_count(client2)
|
|
|
53 |
print(f"An error occurred: {e}")
|
54 |
|
55 |
# Start the monitor thread
|
56 |
+
monitor_thread = Thread(target=monitor_growth, daemon=True)
|
57 |
+
monitor_thread.start()
|
58 |
|
59 |
# Streamlit UI
|
60 |
st.title("Token Count Dashboard")
|
|
|
63 |
growth_speed_placeholder = st.empty()
|
64 |
|
65 |
def update_ui():
|
66 |
+
while not stop_threads:
|
67 |
with state_lock:
|
68 |
token_count_placeholder.metric("Total Token Count", state["prev_total_tokens"])
|
69 |
growth_speed_placeholder.metric("Total Growth Speed", state["total_growth_speed"])
|
70 |
time.sleep(1)
|
71 |
|
72 |
+
update_thread = Thread(target=update_ui, daemon=True)
|
73 |
+
update_thread.start()
|
74 |
+
|
75 |
+
try:
|
76 |
+
while True:
|
77 |
+
time.sleep(1)
|
78 |
+
except KeyboardInterrupt:
|
79 |
+
stop_threads = True
|
80 |
+
monitor_thread.join()
|
81 |
+
update_thread.join()
|