Oscar Wang commited on
Commit
74807c8
·
verified ·
1 Parent(s): 9aa620b

Delete index.html

Browse files
Files changed (1) hide show
  1. index.html +0 -59
index.html DELETED
@@ -1,59 +0,0 @@
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)