Beracles commited on
Commit
f9d919d
·
1 Parent(s): 81aeab2

print time msg

Browse files
Files changed (1) hide show
  1. app.py +53 -35
app.py CHANGED
@@ -9,6 +9,7 @@ from gradio_client import Client
9
  from extract import extract
10
  import app_util
11
  from pgsoft.pgconst.const import service_list, functionality_list, game_list
 
12
 
13
  #######################
14
  # proxy version
@@ -65,57 +66,74 @@ def run(hf_token, service, game, functionality, nlp_command):
65
  if functionality == "AI":
66
  if nlp_command in ["", None]:
67
  return "please make sure the command is not empty"
 
 
 
68
  if service == "download game":
69
  res = app_util.call_clouddisk(service, nlp_command, token)
70
  if res is None:
71
  outp = {"status": "Failure"}
72
  else:
73
  outp = {"status": "OK", "result": json.loads(res)}
74
- return json.dumps(outp)
75
- if service == "upload game":
76
  res = app_util.call_clouddisk(service, nlp_command, token)
77
  if res is None:
78
  outp = {"status": "Failure"}
79
  else:
80
  outp = {"status": "OK", "result": res}
81
- return json.dumps(outp)
82
- if service == "list games":
83
  res = app_util.call_clouddisk(service, nlp_command, token)
84
  if res is None:
85
  outp = {"status": "Failure"}
86
  else:
87
  outp = {"status": "OK", "result": json.loads(res)["result"]}
88
- return json.dumps(outp)
89
-
90
- try:
91
- if service not in service_list[1:]:
92
- t = datetime.now()
93
- t = t.astimezone(ZoneInfo("Asia/Shanghai"))
94
- # t = t.replace(microsecond=0)
95
- print(f"{t} [{user_name}] [{game}] {nlp_command}")
96
- client = Client(
97
- url,
98
- hf_token=token,
99
- verbose=False,
100
- )
101
- res = client.predict(
102
- service,
103
- game,
104
- functionality,
105
- nlp_command, # hidden,
106
- api_name="/predict",
107
- )
108
- outp = json.loads(res)
109
- # add proxy version info to the output
110
- outp["proxy-version"] = proxy_version
111
- outp["user"] = user_name
112
- outp["game"] = game
113
- app_util.call_logger(outp, identity, token)
114
- return json.dumps(outp, indent=4)
115
- except Exception as e:
116
- return (
117
- f"{type(e)}, {str(e)}. \nyou may want to make sure your hf_token is correct"
118
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
 
121
  demo = gr.Interface(
 
9
  from extract import extract
10
  import app_util
11
  from pgsoft.pgconst.const import service_list, functionality_list, game_list
12
+ from pgsoft.pgdate.date_utils import beijing
13
 
14
  #######################
15
  # proxy version
 
66
  if functionality == "AI":
67
  if nlp_command in ["", None]:
68
  return "please make sure the command is not empty"
69
+
70
+ service_start = beijing()
71
+ print(f">>>>>>>>>>>>>>> service starts at {service_start} <<<<<<<<<<<<<<")
72
  if service == "download game":
73
  res = app_util.call_clouddisk(service, nlp_command, token)
74
  if res is None:
75
  outp = {"status": "Failure"}
76
  else:
77
  outp = {"status": "OK", "result": json.loads(res)}
78
+ elif service == "upload game":
 
79
  res = app_util.call_clouddisk(service, nlp_command, token)
80
  if res is None:
81
  outp = {"status": "Failure"}
82
  else:
83
  outp = {"status": "OK", "result": res}
84
+ elif service == "list games":
 
85
  res = app_util.call_clouddisk(service, nlp_command, token)
86
  if res is None:
87
  outp = {"status": "Failure"}
88
  else:
89
  outp = {"status": "OK", "result": json.loads(res)["result"]}
90
+ else:
91
+ try:
92
+ if service not in service_list[1:]:
93
+ t = datetime.now()
94
+ t = t.astimezone(ZoneInfo("Asia/Shanghai"))
95
+ # t = t.replace(microsecond=0)
96
+ print(f"{t} [{user_name}] [{game}] {nlp_command}")
97
+ client = Client(
98
+ url,
99
+ hf_token=token,
100
+ verbose=False,
101
+ )
102
+ calling_start = beijing()
103
+ print(f"calling ai starts at {calling_start}")
104
+ res = client.predict(
105
+ service,
106
+ game,
107
+ functionality,
108
+ nlp_command, # hidden,
109
+ api_name="/predict",
110
+ )
111
+ calling_end = beijing()
112
+ timecost = calling_end.timestamp() - calling_start.timestamp()
113
+ print(f"calling ai ends at {calling_end}, costs %.2fs" % timecost)
114
+ outp = json.loads(res)
115
+ # add proxy version info to the output
116
+ outp["proxy-version"] = proxy_version
117
+ outp["user"] = user_name
118
+ outp["game"] = game
119
+ calling_start = beijing()
120
+ print(f"calling logger starts at {beijing()}")
121
+ app_util.call_logger(outp, identity, token)
122
+ calling_end = beijing()
123
+ timecost = calling_end.timestamp() - calling_start.timestamp()
124
+ print(f"calling logger ends at {calling_end}, costs %.2fs" % timecost)
125
+ except Exception as e:
126
+ return (
127
+ f"{type(e)}, {str(e)}. \nyou may want to make "
128
+ + "sure your hf_token is correct"
129
+ )
130
+ service_end = beijing()
131
+ timecost = service_end.timestamp() - service_start.timestamp()
132
+ print(
133
+ f">>>>>>>>>>>>>>> service ends at {service_end}, costs %.2f <<<<<<<<<<<<<<<"
134
+ % timecost
135
+ )
136
+ return json.dumps(outp, indent=4)
137
 
138
 
139
  demo = gr.Interface(