oscarwang2 commited on
Commit
b7dd373
·
verified ·
1 Parent(s): 8b929e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -32
app.py CHANGED
@@ -1,7 +1,6 @@
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")
@@ -24,37 +23,27 @@ def get_token_count(client):
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"]
36
- total_tokens = curr_count1 + curr_count2 + curr_count3
37
- total_growth_speed = growth_speed1 + growth_speed2 + growth_speed3
38
-
39
- state["prev_count1"] = curr_count1
40
- state["prev_count2"] = curr_count2
41
- state["prev_count3"] = curr_count3
42
- state["prev_total_tokens"] = total_tokens
43
- state["total_growth_speed"] = total_growth_speed
44
-
45
- time.sleep(5)
46
- except Exception as e:
47
- print(f"Error in monitor growth: {e}")
48
-
49
- # Start the monitor thread
50
- Thread(target=monitor_growth, daemon=True).start()
51
-
52
- def get_dashboard_metrics():
53
- return state["prev_total_tokens"], state["total_growth_speed"]
54
-
55
  def update_dashboard():
56
- tokens, speed = get_dashboard_metrics()
57
- return tokens, speed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
  # Create Gradio Interface
60
  with gr.Blocks() as demo:
 
1
  import gradio as gr
2
  from gradio_client import Client
3
+ import threading
 
4
 
5
  # Initialize clients
6
  client1 = Client("orionai/training-data-collection_2")
 
23
  print(f"Error fetching token count: {e}")
24
  return 0
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  def update_dashboard():
27
+ try:
28
+ curr_count1 = get_token_count(client1)
29
+ curr_count2 = get_token_count(client2)
30
+ curr_count3 = get_token_count(client3)
31
+ growth_speed1 = curr_count1 - state["prev_count1"]
32
+ growth_speed2 = curr_count2 - state["prev_count2"]
33
+ growth_speed3 = curr_count3 - state["prev_count3"]
34
+ total_tokens = curr_count1 + curr_count2 + curr_count3
35
+ total_growth_speed = growth_speed1 + growth_speed2 + growth_speed3
36
+
37
+ state["prev_count1"] = curr_count1
38
+ state["prev_count2"] = curr_count2
39
+ state["prev_count3"] = curr_count3
40
+ state["prev_total_tokens"] = total_tokens
41
+ state["total_growth_speed"] = total_growth_speed
42
+
43
+ return total_tokens, total_growth_speed
44
+ except Exception as e:
45
+ print(f"Error in update dashboard: {e}")
46
+ return 0, 0
47
 
48
  # Create Gradio Interface
49
  with gr.Blocks() as demo: