Beracles
commited on
Commit
·
f9d919d
1
Parent(s):
81aeab2
print time msg
Browse files
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 |
-
|
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 |
-
|
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 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
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(
|