Spaces:
Runtime error
Runtime error
oscarwang2
commited on
Commit
•
0017ad2
1
Parent(s):
9efeb57
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from gradio_client import Client
|
|
|
|
|
3 |
|
4 |
# Initialize clients
|
5 |
client1 = Client("orionai/training-data-collection_2")
|
@@ -14,6 +16,8 @@ state = {
|
|
14 |
"total_growth_speed": 0
|
15 |
}
|
16 |
|
|
|
|
|
17 |
def get_token_count(client):
|
18 |
try:
|
19 |
result = client.predict(api_name="/update_token_display")
|
@@ -27,19 +31,22 @@ def update_dashboard():
|
|
27 |
curr_count1 = get_token_count(client1)
|
28 |
curr_count2 = get_token_count(client2)
|
29 |
curr_count3 = get_token_count(client3)
|
30 |
-
|
31 |
-
growth_speed2 = curr_count2 - state["prev_count2"]
|
32 |
-
growth_speed3 = curr_count3 - state["prev_count3"]
|
33 |
total_tokens = curr_count1 + curr_count2 + curr_count3
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
36 |
state["prev_count1"] = curr_count1
|
37 |
state["prev_count2"] = curr_count2
|
38 |
state["prev_count3"] = curr_count3
|
39 |
state["prev_total_tokens"] = total_tokens
|
40 |
-
state["total_growth_speed"] =
|
41 |
|
42 |
-
return total_tokens,
|
43 |
except Exception as e:
|
44 |
print(f"Error in update dashboard: {e}")
|
45 |
return 0, 0
|
@@ -53,7 +60,7 @@ with gr.Blocks() as demo:
|
|
53 |
gr.Markdown("# Token Count Dashboard")
|
54 |
|
55 |
total_tokens = gr.Number(label="Total Token Count")
|
56 |
-
growth_speed = gr.Number(label="
|
57 |
|
58 |
update_button = gr.Button("Update Stats")
|
59 |
update_button.click(fn=refresh_metrics, inputs=[], outputs=[total_tokens, growth_speed])
|
|
|
1 |
import gradio as gr
|
2 |
from gradio_client import Client
|
3 |
+
import time
|
4 |
+
from collections import deque
|
5 |
|
6 |
# Initialize clients
|
7 |
client1 = Client("orionai/training-data-collection_2")
|
|
|
16 |
"total_growth_speed": 0
|
17 |
}
|
18 |
|
19 |
+
token_counts = deque(maxlen=60) # Store up to 60 seconds of token counts
|
20 |
+
|
21 |
def get_token_count(client):
|
22 |
try:
|
23 |
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 |
total_tokens = curr_count1 + curr_count2 + curr_count3
|
36 |
+
token_counts.append(total_tokens)
|
37 |
+
|
38 |
+
if len(token_counts) > 1:
|
39 |
+
growth_speed = (token_counts[-1] - token_counts[0]) / len(token_counts)
|
40 |
+
else:
|
41 |
+
growth_speed = 0
|
42 |
+
|
43 |
state["prev_count1"] = curr_count1
|
44 |
state["prev_count2"] = curr_count2
|
45 |
state["prev_count3"] = curr_count3
|
46 |
state["prev_total_tokens"] = total_tokens
|
47 |
+
state["total_growth_speed"] = growth_speed
|
48 |
|
49 |
+
return total_tokens, growth_speed
|
50 |
except Exception as e:
|
51 |
print(f"Error in update dashboard: {e}")
|
52 |
return 0, 0
|
|
|
60 |
gr.Markdown("# Token Count Dashboard")
|
61 |
|
62 |
total_tokens = gr.Number(label="Total Token Count")
|
63 |
+
growth_speed = gr.Number(label="Average Growth Speed (per second over the last minute)")
|
64 |
|
65 |
update_button = gr.Button("Update Stats")
|
66 |
update_button.click(fn=refresh_metrics, inputs=[], outputs=[total_tokens, growth_speed])
|