File size: 1,705 Bytes
111b72c
 
 
5924ba7
111b72c
 
4c9c4c6
111b72c
 
 
5924ba7
 
 
111b72c
4c9c4c6
 
111b72c
 
 
 
 
4c9c4c6
 
111b72c
4c9c4c6
 
111b72c
4c9c4c6
5924ba7
 
 
 
111b72c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import json

from gradio_client import Client
from pgsoft.pgdate.date_utils import beijing


def call_logger(log_info, caller, hf_token) -> None:
    #######################
    # logging
    #######################
    calling_start = beijing()
    print(f"calling logger starts at {beijing()}")
    #################################################
    urls = [
        "https://hubei-hunan-logger.hf.space",
        "https://hubei-hunan-logger2.hf.space",
    ]
    for url in urls:
        try:
            client = Client(
                url,
                hf_token=hf_token,
                verbose=False,
            )
            client.submit(json.dumps(log_info), caller)
            print(f"[logging to {url}] OK")
        except Exception as e:
            print(f"[logging to {url}] error: {e}")
    #################################################
    calling_end = beijing()
    timecost = calling_end.timestamp() - calling_start.timestamp()
    print(f"calling logger ends at {calling_end}, costs {timecost:.2f}s")


def call_clouddisk(service, arg, hf_token) -> str | None:
    ##########################
    # upload or download game
    ##########################
    urls = [
        "https://pgsoft-clouddisk.hf.space",
        # "https://pgsoft-clouddisk2.hf.space",
    ]

    for url in urls:
        try:
            client = Client(
                url,
                hf_token=hf_token,
                verbose=False,
            )
            res = client.predict(service, arg, api_name="/predict")
            print("[call_clouddisk] OK")
            return res
        except Exception as e:
            print(f"[call_clouddisk] {type(e)}: {e}")
            return None