oscarwang2 commited on
Commit
d4d61a5
1 Parent(s): 334f993

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +59 -35
index.html CHANGED
@@ -1,35 +1,59 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Token Count Dashboard</title>
7
- <script src="https://cdn.tailwindcss.com"></script>
8
- <script>
9
- async function fetchStats() {
10
- const response = await fetch('/stats');
11
- const data = await response.json();
12
- document.getElementById('total_tokens').innerText = data.total_tokens;
13
- document.getElementById('growth_speed').innerText = data.total_growth_speed;
14
- }
15
-
16
- function startUpdatingStats() {
17
- fetchStats();
18
- setInterval(fetchStats, 1000);
19
- }
20
-
21
- document.addEventListener('DOMContentLoaded', startUpdatingStats);
22
- </script>
23
- </head>
24
- <body class="bg-gray-100 text-gray-900 flex items-center justify-center h-screen">
25
- <div class="p-6 max-w-sm mx-auto bg-white rounded-xl shadow-md space-y-4">
26
- <div class="text-center text-xl font-semibold">Token Count Dashboard</div>
27
- <div class="text-lg">
28
- <span>Total Token Count:</span> <span id="total_tokens">0</span>
29
- </div>
30
- <div class="text-lg">
31
- <span>Total Growth Speed:</span> <span id="growth_speed">0</span>
32
- </div>
33
- </div>
34
- </body>
35
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, jsonify
2
+ from threading import Thread
3
+ import time
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
+ app = Flask(__name__)
9
+
10
+ # Initialize clients with retry and timeout settings
11
+ client1 = Client("orionai/training-data-collection_2")
12
+ client2 = Client("orionai/training-data-collection_3")
13
+ client3 = Client("orionai/training-data-collection")
14
+
15
+ state = {
16
+ "prev_count1": 0,
17
+ "prev_count2": 0,
18
+ "prev_count3": 0,
19
+ "prev_total_tokens": 0,
20
+ "total_growth_speed": 0
21
+ }
22
+
23
+ @retry(stop=stop_after_attempt(3), wait=wait_fixed(2), retry=retry_if_exception_type(httpx.ReadTimeout))
24
+ def get_token_count():
25
+ result1 = client1.predict(api_name="/update_token_display", timeout=10.0)
26
+ result2 = client2.predict(api_name="/update_token_display", timeout=10.0)
27
+ result3 = client3.predict(api_name="/update_token_display", timeout=10.0)
28
+ return int(result1), int(result2), int(result3)
29
+
30
+ def monitor_growth():
31
+ while True:
32
+ try:
33
+ curr_count1, curr_count2, curr_count3 = get_token_count()
34
+ growth_speed1 = curr_count1 - state["prev_count1"]
35
+ growth_speed2 = curr_count2 - state["prev_count2"]
36
+ growth_speed3 = curr_count3 - state["prev_count3"]
37
+ total_tokens = curr_count1 + curr_count2 + curr_count3
38
+ total_growth_speed = growth_speed1 + growth_speed2 + growth_speed3
39
+
40
+ state["prev_count1"] = curr_count1
41
+ state["prev_count2"] = curr_count2
42
+ state["prev_count3"] = curr_count3
43
+ state["prev_total_tokens"] = total_tokens
44
+ state["total_growth_speed"] = total_growth_speed
45
+ except httpx.ReadTimeout:
46
+ print("Timeout occurred while fetching token count.")
47
+ time.sleep(1)
48
+
49
+ Thread(target=monitor_growth, daemon=True).start()
50
+
51
+ @app.route('/stats', methods=['GET'])
52
+ def get_stats():
53
+ return jsonify({
54
+ "total_tokens": state["prev_total_tokens"],
55
+ "total_growth_speed": state["total_growth_speed"]
56
+ })
57
+
58
+ if __name__ == '__main__':
59
+ app.run(debug=True)