oscarwang2 commited on
Commit
bccb968
1 Parent(s): 0017ad2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -7
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import gradio as gr
2
  from gradio_client import Client
3
- import time
4
  from collections import deque
5
 
6
  # Initialize clients
@@ -8,6 +7,14 @@ 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,
13
  "prev_count2": 0,
@@ -19,14 +26,16 @@ state = {
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")
24
  return int(result)
25
  except Exception as e:
26
- print(f"Error fetching token count: {e}")
27
  return 0
28
 
29
  def update_dashboard():
 
30
  try:
31
  curr_count1 = get_token_count(client1)
32
  curr_count2 = get_token_count(client2)
@@ -45,15 +54,26 @@ def update_dashboard():
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
53
 
54
  def refresh_metrics():
55
- tokens, speed = update_dashboard()
56
- return tokens, speed
 
57
 
58
  # Create Gradio Interface
59
  with gr.Blocks() as demo:
@@ -61,8 +81,10 @@ with gr.Blocks() as demo:
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])
67
 
68
  demo.launch()
 
1
  import gradio as gr
2
  from gradio_client import Client
 
3
  from collections import deque
4
 
5
  # Initialize clients
 
7
  client2 = Client("orionai/training-data-collection_3")
8
  client3 = Client("orionai/training-data-collection")
9
 
10
+ # URLs for the clients
11
+ urls = {
12
+ client1: "https://orionai-training-data-collection-2.hf.space",
13
+ client2: "https://orionai-training-data-collection-3.hf.space",
14
+ client3: "https://orionai-training-data-collection.hf.space"
15
+ }
16
+
17
+ # Initialize state variables
18
  state = {
19
  "prev_count1": 0,
20
  "prev_count2": 0,
 
26
  token_counts = deque(maxlen=60) # Store up to 60 seconds of token counts
27
 
28
  def get_token_count(client):
29
+ """Fetch the token count from a client."""
30
  try:
31
  result = client.predict(api_name="/update_token_display")
32
  return int(result)
33
  except Exception as e:
34
+ print(f"Error fetching token count from {client.host}: {e}")
35
  return 0
36
 
37
  def update_dashboard():
38
+ """Update the token count and growth speed."""
39
  try:
40
  curr_count1 = get_token_count(client1)
41
  curr_count2 = get_token_count(client2)
 
54
  state["prev_count3"] = curr_count3
55
  state["prev_total_tokens"] = total_tokens
56
  state["total_growth_speed"] = growth_speed
57
+
58
+ counts = {
59
+ client1: curr_count1,
60
+ client2: curr_count2,
61
+ client3: curr_count3
62
+ }
63
+
64
+ max_client = max(counts, key=counts.get)
65
+ max_tokens = counts[max_client]
66
+ max_url = urls[max_client]
67
 
68
+ return total_tokens, growth_speed, max_tokens, max_url
69
  except Exception as e:
70
  print(f"Error in update dashboard: {e}")
71
+ return 0, 0, 0, ""
72
 
73
  def refresh_metrics():
74
+ """Refresh the metrics for the dashboard."""
75
+ tokens, speed, max_tokens, max_url = update_dashboard()
76
+ return tokens, speed, max_tokens, max_url
77
 
78
  # Create Gradio Interface
79
  with gr.Blocks() as demo:
 
81
 
82
  total_tokens = gr.Number(label="Total Token Count")
83
  growth_speed = gr.Number(label="Average Growth Speed (per second over the last minute)")
84
+ max_tokens = gr.Number(label="Max Token Count from a Single App")
85
+ max_url = gr.HTML(label="Link to App with Max Tokens")
86
 
87
  update_button = gr.Button("Update Stats")
88
+ update_button.click(fn=refresh_metrics, inputs=[], outputs=[total_tokens, growth_speed, max_tokens, max_url])
89
 
90
  demo.launch()