oscarwang2 commited on
Commit
fc6943d
1 Parent(s): bd98967

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -82
app.py DELETED
@@ -1,82 +0,0 @@
1
- import streamlit as st
2
- import time
3
- from threading import Thread, Lock
4
- from gradio_client import Client
5
- from tenacity import retry, stop_after_attempt, wait_fixed, retry_if_exception_type
6
- import httpx
7
-
8
- # Initialize clients
9
- client1 = Client("orionai/training-data-collection_2")
10
- client2 = Client("orionai/training-data-collection_3")
11
- client3 = Client("orionai/training-data-collection")
12
-
13
- state = {
14
- "prev_count1": 0,
15
- "prev_count2": 0,
16
- "prev_count3": 0,
17
- "prev_total_tokens": 0,
18
- "total_growth_speed": 0
19
- }
20
-
21
- state_lock = Lock()
22
-
23
- @retry(stop=stop_after_attempt(3), wait=wait_fixed(2), retry=retry_if_exception_type(httpx.ReadTimeout))
24
- def get_token_count(client):
25
- result = client.predict(api_name="/update_token_display")
26
- return int(result)
27
-
28
- def monitor_growth():
29
- while True:
30
- try:
31
- curr_count1 = get_token_count(client1)
32
- curr_count2 = get_token_count(client2)
33
- curr_count3 = get_token_count(client3)
34
-
35
- with state_lock:
36
- growth_speed1 = curr_count1 - state["prev_count1"]
37
- growth_speed2 = curr_count2 - state["prev_count2"]
38
- growth_speed3 = curr_count3 - state["prev_count3"]
39
- total_tokens = curr_count1 + curr_count2 + curr_count3
40
- total_growth_speed = growth_speed1 + growth_speed2 + growth_speed3
41
-
42
- state["prev_count1"] = curr_count1
43
- state["prev_count2"] = curr_count2
44
- state["prev_count3"] = curr_count3
45
- state["prev_total_tokens"] = total_tokens
46
- state["total_growth_speed"] = total_growth_speed
47
-
48
- time.sleep(5) # Increased sleep duration
49
- except httpx.ReadTimeout:
50
- print("Timeout occurred while fetching token count.")
51
- except Exception as e:
52
- print(f"An error occurred: {e}")
53
-
54
- # Start the monitor thread
55
- monitor_thread = Thread(target=monitor_growth, daemon=True)
56
- monitor_thread.start()
57
-
58
- # Streamlit UI
59
- st.title("Token Count Dashboard")
60
-
61
- token_count_placeholder = st.empty()
62
- growth_speed_placeholder = st.empty()
63
-
64
- def update_ui():
65
- while True:
66
- with state_lock:
67
- token_count_placeholder.metric("Total Token Count", state["prev_total_tokens"])
68
- growth_speed_placeholder.metric("Total Growth Speed", state["total_growth_speed"])
69
- time.sleep(1)
70
- st.experimental_rerun()
71
-
72
- # Start the update UI thread
73
- update_thread = Thread(target=update_ui, daemon=True)
74
- update_thread.start()
75
-
76
- # Keep the app running
77
- try:
78
- while True:
79
- time.sleep(1)
80
- except KeyboardInterrupt:
81
- monitor_thread.join()
82
- update_thread.join()