Spaces:
Runtime error
Runtime error
File size: 1,936 Bytes
93a340f 0f255ad 93a340f 0f255ad 8b929e1 0f255ad 93a340f 0f255ad 93a340f 0f255ad 93a340f b28269b b7dd373 b28269b 9efeb57 93a340f b28269b 9efeb57 93a340f b28269b 9efeb57 b28269b 93a340f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 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 55 56 57 58 59 60 61 62 |
import gradio as gr
from gradio_client import Client
# Initialize clients
client1 = Client("orionai/training-data-collection_2")
client2 = Client("orionai/training-data-collection_3")
client3 = Client("orionai/training-data-collection")
state = {
"prev_count1": 0,
"prev_count2": 0,
"prev_count3": 0,
"prev_total_tokens": 0,
"total_growth_speed": 0
}
def get_token_count(client):
try:
result = client.predict(api_name="/update_token_display")
return int(result)
except Exception as e:
print(f"Error fetching token count: {e}")
return 0
def update_dashboard():
try:
curr_count1 = get_token_count(client1)
curr_count2 = get_token_count(client2)
curr_count3 = get_token_count(client3)
growth_speed1 = curr_count1 - state["prev_count1"]
growth_speed2 = curr_count2 - state["prev_count2"]
growth_speed3 = curr_count3 - state["prev_count3"]
total_tokens = curr_count1 + curr_count2 + curr_count3
total_growth_speed = growth_speed1 + growth_speed2 + growth_speed3
state["prev_count1"] = curr_count1
state["prev_count2"] = curr_count2
state["prev_count3"] = curr_count3
state["prev_total_tokens"] = total_tokens
state["total_growth_speed"] = total_growth_speed
return total_tokens, total_growth_speed
except Exception as e:
print(f"Error in update dashboard: {e}")
return 0, 0
def refresh_metrics():
tokens, speed = update_dashboard()
return tokens, speed
# Create Gradio Interface
with gr.Blocks() as demo:
gr.Markdown("# Token Count Dashboard")
total_tokens = gr.Number(label="Total Token Count")
growth_speed = gr.Number(label="Total Growth Speed")
update_button = gr.Button("Update Stats")
update_button.click(fn=refresh_metrics, inputs=[], outputs=[total_tokens, growth_speed])
demo.launch()
|