Beracles commited on
Commit
5d5cb75
·
1 Parent(s): 1d4c378

use new logger api

Browse files
Files changed (3) hide show
  1. app.py +1 -1
  2. call_logger.py +38 -19
  3. requirements-local.txt +1 -1
app.py CHANGED
@@ -22,7 +22,7 @@ t = t.astimezone(ZoneInfo("America/Los_Angeles"))
22
  print(f"[Seattle]: {t.replace(microsecond=0)}")
23
 
24
 
25
- identity = os.environ.get("identity")
26
  print(f"identity: {identity}")
27
  db_token = os.environ.get("db_token")
28
  if db_token:
 
22
  print(f"[Seattle]: {t.replace(microsecond=0)}")
23
 
24
 
25
+ identity = os.environ.get("identity", "local")
26
  print(f"identity: {identity}")
27
  db_token = os.environ.get("db_token")
28
  if db_token:
call_logger.py CHANGED
@@ -1,32 +1,51 @@
1
  import json
2
-
3
- from gradio_client import Client
4
  from pgsoft.pgdate.date_utils import beijing
5
 
6
 
7
- def call_logger(log_info, caller, hf_token) -> None:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  #######################
9
  # logging
10
  #######################
11
  calling_start = beijing()
12
  print(f"[{calling_start}] logging starts")
13
  #################################################
14
- urls = [
15
- "https://hubei-hunan-logger.hf.space",
16
- "https://hubei-hunan-logger2.hf.space",
17
- ]
18
- for url in urls:
19
- try:
20
- client = Client(
21
- url,
22
- hf_token=hf_token,
23
- verbose=False,
24
- )
25
- client.submit(json.dumps(log_info), caller)
26
- print(f"[logging to {url}] OK")
27
- return None
28
- except Exception as e:
29
- print(f"[logging to {url}] Failed, {type(e)}: {e}")
30
  #################################################
31
  calling_end = beijing()
32
  timecost = calling_end.timestamp() - calling_start.timestamp()
 
1
  import json
2
+ import requests
 
3
  from pgsoft.pgdate.date_utils import beijing
4
 
5
 
6
+ url_base = "https://hubei-hunan-logger.hf.space"
7
+ url_add = f"{url_base}/add"
8
+
9
+
10
+ def post_to_logger_helper(log, caller, token):
11
+ header = {
12
+ "accept": "application/json",
13
+ "Content-Type": "application/json",
14
+ "Authorization": f"Bearer {token}",
15
+ }
16
+ myobj = {
17
+ "log": log,
18
+ "caller": caller,
19
+ }
20
+ try:
21
+ res = requests.post(url_add, headers=header, json=myobj)
22
+ content = res.json()
23
+ if res.status_code == 200:
24
+ timestamp = content["timestamp"]
25
+ command = content["command"]
26
+ status = content["status"]
27
+ print(f"[{timestamp}] [{command}] [{status}]")
28
+ return True
29
+ else:
30
+ print(res.text)
31
+ return False
32
+ except Exception as e:
33
+ print(f"{type(e)}: {e}")
34
+ return False
35
+
36
+
37
+ def call_logger(log_info, caller, token) -> None:
38
  #######################
39
  # logging
40
  #######################
41
  calling_start = beijing()
42
  print(f"[{calling_start}] logging starts")
43
  #################################################
44
+ res = post_to_logger_helper(json.dumps(log_info), caller, token)
45
+ if res:
46
+ print(f"[logging to {url_base}] OK")
47
+ else:
48
+ print(f"[logging to {url_base}] Failed")
 
 
 
 
 
 
 
 
 
 
 
49
  #################################################
50
  calling_end = beijing()
51
  timecost = calling_end.timestamp() - calling_start.timestamp()
requirements-local.txt CHANGED
@@ -1,3 +1,3 @@
1
  pytest
2
- gradio==4.39.0
3
  git+ssh://git@github.com/east-and-west-magic/pgsoft.git@tag-2024-01-11-a
 
1
  pytest
2
+ gradio==4.44.1
3
  git+ssh://git@github.com/east-and-west-magic/pgsoft.git@tag-2024-01-11-a