Spaces:
Runtime error
Runtime error
Oscar Wang
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
-
|
2 |
-
from threading import Thread
|
3 |
import time
|
|
|
4 |
from gradio_client import Client
|
5 |
-
|
6 |
-
|
7 |
|
8 |
# Initialize clients
|
9 |
client1 = Client("orionai/training-data-collection_2")
|
@@ -18,37 +18,46 @@ state = {
|
|
18 |
"total_growth_speed": 0
|
19 |
}
|
20 |
|
|
|
21 |
def get_token_count():
|
22 |
-
result1 = client1.predict(api_name="/update_token_display")
|
23 |
-
result2 = client2.predict(api_name="/update_token_display")
|
24 |
-
result3 = client3.predict(api_name="/update_token_display")
|
25 |
return int(result1), int(result2), int(result3)
|
26 |
|
27 |
def monitor_growth():
|
28 |
while True:
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
|
|
|
43 |
|
44 |
-
|
|
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
"
|
50 |
-
|
51 |
-
})
|
52 |
|
53 |
-
|
54 |
-
app.run(debug=True)
|
|
|
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
|
7 |
|
8 |
# Initialize clients
|
9 |
client1 = Client("orionai/training-data-collection_2")
|
|
|
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():
|
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"]
|
35 |
+
total_tokens = curr_count1 + curr_count2 + curr_count3
|
36 |
+
total_growth_speed = growth_speed1 + growth_speed2 + growth_speed3
|
37 |
+
|
38 |
+
state["prev_count1"] = curr_count1
|
39 |
+
state["prev_count2"] = curr_count2
|
40 |
+
state["prev_count3"] = curr_count3
|
41 |
+
state["prev_total_tokens"] = total_tokens
|
42 |
+
state["total_growth_speed"] = total_growth_speed
|
43 |
+
|
44 |
+
time.sleep(1)
|
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()
|
50 |
|
51 |
+
# Streamlit UI
|
52 |
+
st.title("Token Count Dashboard")
|
53 |
|
54 |
+
token_count_placeholder = st.empty()
|
55 |
+
growth_speed_placeholder = st.empty()
|
56 |
|
57 |
+
def update_ui():
|
58 |
+
while True:
|
59 |
+
token_count_placeholder.metric("Total Token Count", state["prev_total_tokens"])
|
60 |
+
growth_speed_placeholder.metric("Total Growth Speed", state["total_growth_speed"])
|
61 |
+
time.sleep(1)
|
|
|
62 |
|
63 |
+
Thread(target=update_ui, daemon=True).start()
|
|