Spaces:
Runtime error
Runtime error
oscarwang2
commited on
Commit
•
0f255ad
1
Parent(s):
93a340f
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
import time
|
4 |
from threading import Thread
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
|
11 |
state = {
|
12 |
"prev_count1": 0,
|
@@ -16,22 +16,20 @@ state = {
|
|
16 |
"total_growth_speed": 0
|
17 |
}
|
18 |
|
19 |
-
def get_token_count(
|
20 |
try:
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
except (requests.RequestException, ValueError) as e:
|
26 |
-
print(f"Error fetching token count from {url}: {e}")
|
27 |
return 0
|
28 |
|
29 |
def monitor_growth():
|
30 |
while True:
|
31 |
try:
|
32 |
-
curr_count1 = get_token_count(
|
33 |
-
curr_count2 = get_token_count(
|
34 |
-
curr_count3 = get_token_count(
|
35 |
growth_speed1 = curr_count1 - state["prev_count1"]
|
36 |
growth_speed2 = curr_count2 - state["prev_count2"]
|
37 |
growth_speed3 = curr_count3 - state["prev_count3"]
|
@@ -62,9 +60,10 @@ with gr.Blocks() as demo:
|
|
62 |
|
63 |
def update_dashboard():
|
64 |
tokens, speed = get_dashboard_metrics()
|
65 |
-
|
|
|
66 |
|
67 |
# Automatically update the metrics every 5 seconds
|
68 |
-
gr.Timer(
|
69 |
|
70 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from gradio_client import Client
|
3 |
import time
|
4 |
from threading import Thread
|
5 |
|
6 |
+
# Initialize clients
|
7 |
+
client1 = Client("orionai/training-data-collection-2")
|
8 |
+
client2 = Client("orionai/training-data-collection-3")
|
9 |
+
client3 = Client("orionai/training-data-collection")
|
10 |
|
11 |
state = {
|
12 |
"prev_count1": 0,
|
|
|
16 |
"total_growth_speed": 0
|
17 |
}
|
18 |
|
19 |
+
def get_token_count(client):
|
20 |
try:
|
21 |
+
result = client.predict(api_name="/update_token_display")
|
22 |
+
return int(result)
|
23 |
+
except Exception as e:
|
24 |
+
print(f"Error fetching token count: {e}")
|
|
|
|
|
25 |
return 0
|
26 |
|
27 |
def monitor_growth():
|
28 |
while True:
|
29 |
try:
|
30 |
+
curr_count1 = get_token_count(client1)
|
31 |
+
curr_count2 = get_token_count(client2)
|
32 |
+
curr_count3 = get_token_count(client3)
|
33 |
growth_speed1 = curr_count1 - state["prev_count1"]
|
34 |
growth_speed2 = curr_count2 - state["prev_count2"]
|
35 |
growth_speed3 = curr_count3 - state["prev_count3"]
|
|
|
60 |
|
61 |
def update_dashboard():
|
62 |
tokens, speed = get_dashboard_metrics()
|
63 |
+
total_tokens.update(value=tokens)
|
64 |
+
growth_speed.update(value=speed)
|
65 |
|
66 |
# Automatically update the metrics every 5 seconds
|
67 |
+
gr.Timer(5, update_dashboard)
|
68 |
|
69 |
demo.launch()
|