Beracles commited on
Commit
572ca12
·
1 Parent(s): 025d8b8

add dev pipeline

Browse files
Files changed (2) hide show
  1. app.py +20 -10
  2. app_util.py +14 -19
app.py CHANGED
@@ -23,18 +23,27 @@ t = t.astimezone(ZoneInfo("America/Los_Angeles"))
23
  print(f"[Seattle]: {t.replace(microsecond=0)}")
24
 
25
 
26
- spaces = {
27
  "b_demo_hf": "stevez-ai",
28
  "pgdemo2": "stevez-ai2",
29
- "pgdemo3": "stevez-ai3",
 
 
 
 
 
 
30
  }
31
 
32
  identity = os.environ.get("identity")
33
  if not identity:
34
  identity = "b_demo_hf"
35
- space = "stevez-ai"
36
- if identity in spaces:
37
- space = spaces[identity]
 
 
 
38
 
39
 
40
  def run(hf_token, service, game, functionality, nlp_command):
@@ -48,10 +57,11 @@ def run(hf_token, service, game, functionality, nlp_command):
48
  user_name = "__fake__"
49
 
50
  # redirect all traffic to the proxy sever
51
- global space
52
  if redirect is not None:
53
- space = redirect
54
- url = f"https://{space}.hf.space"
 
55
 
56
  if token is None or token == "":
57
  return "please specify hf token"
@@ -68,7 +78,7 @@ def run(hf_token, service, game, functionality, nlp_command):
68
  service_start = beijing()
69
  print(f"<<<<<<<<<<<<<< service starts at {service_start} <<<<<<<<<<<<<<")
70
  if service in ["download game", "upload game", "list games"]:
71
- res = app_util.call_clouddisk(service, nlp_command, token)
72
  res = json.loads(res)
73
  if res["result"] is None:
74
  outp = {"status": "Failure"}
@@ -85,7 +95,7 @@ def run(hf_token, service, game, functionality, nlp_command):
85
  game,
86
  functionality,
87
  nlp_command,
88
- url,
89
  token,
90
  )
91
  if isinstance(outp, str):
 
23
  print(f"[Seattle]: {t.replace(microsecond=0)}")
24
 
25
 
26
+ ais = {
27
  "b_demo_hf": "stevez-ai",
28
  "pgdemo2": "stevez-ai2",
29
+ "pgdemo_dev": "stevez-ai3",
30
+ }
31
+
32
+ clouddisks = {
33
+ "b_demo_hf": "pgsoft-clouddisk",
34
+ "pgdemo2": "pgsoft-clouddisk",
35
+ "pgdemo_dev": "pgsoft-clouddisk_dev",
36
  }
37
 
38
  identity = os.environ.get("identity")
39
  if not identity:
40
  identity = "b_demo_hf"
41
+ ai = "stevez-ai"
42
+ if identity in ais:
43
+ ai = ais[identity]
44
+ clouddisk = "clouddisk"
45
+ if identity in clouddisks:
46
+ clouddisk = clouddisks[identity]
47
 
48
 
49
  def run(hf_token, service, game, functionality, nlp_command):
 
57
  user_name = "__fake__"
58
 
59
  # redirect all traffic to the proxy sever
60
+ global ai
61
  if redirect is not None:
62
+ ai = redirect
63
+ ai_url = f"https://{ai}.hf.space"
64
+ clouddisk_url = f"https://{clouddisk}.hf.space"
65
 
66
  if token is None or token == "":
67
  return "please specify hf token"
 
78
  service_start = beijing()
79
  print(f"<<<<<<<<<<<<<< service starts at {service_start} <<<<<<<<<<<<<<")
80
  if service in ["download game", "upload game", "list games"]:
81
+ res = app_util.call_clouddisk(clouddisk_url, service, nlp_command, token)
82
  res = json.loads(res)
83
  if res["result"] is None:
84
  outp = {"status": "Failure"}
 
95
  game,
96
  functionality,
97
  nlp_command,
98
+ ai_url,
99
  token,
100
  )
101
  if isinstance(outp, str):
app_util.py CHANGED
@@ -1,4 +1,5 @@
1
  import json
 
2
 
3
  from gradio_client import Client
4
  from pgsoft.pgdate.date_utils import beijing
@@ -32,25 +33,19 @@ def call_logger(log_info, caller, hf_token) -> None:
32
  print(f"calling logger ends at {calling_end}, costs {timecost:.2f}s")
33
 
34
 
35
- def call_clouddisk(service, arg, hf_token) -> str | None:
36
  ##########################
37
  # upload or download game
38
  ##########################
39
- urls = [
40
- "https://pgsoft-clouddisk.hf.space",
41
- # "https://pgsoft-clouddisk2.hf.space",
42
- ]
43
-
44
- for url in urls:
45
- try:
46
- client = Client(
47
- url,
48
- hf_token=hf_token,
49
- verbose=False,
50
- )
51
- res = client.predict(service, arg, api_name="/predict")
52
- print("[call_clouddisk] OK")
53
- return res
54
- except Exception as e:
55
- print(f"[call_clouddisk] {type(e)}: {e}")
56
- return None
 
1
  import json
2
+ import os
3
 
4
  from gradio_client import Client
5
  from pgsoft.pgdate.date_utils import beijing
 
33
  print(f"calling logger ends at {calling_end}, costs {timecost:.2f}s")
34
 
35
 
36
+ def call_clouddisk(url: str, service, arg, hf_token) -> str | None:
37
  ##########################
38
  # upload or download game
39
  ##########################
40
+ try:
41
+ client = Client(
42
+ url,
43
+ hf_token=hf_token,
44
+ verbose=False,
45
+ )
46
+ res = client.predict(service, arg, api_name="/predict")
47
+ print(f"[call_clouddisk] {service} from {url} [OK]")
48
+ return res
49
+ except Exception as e:
50
+ print(f"[call_clouddisk] {type(e)}: {e}")
51
+ return None