steveagi commited on
Commit
86a9ccf
·
unverified ·
2 Parent(s): 025d8b8 182d803

Merge pull request #17 from east-and-west-magic/feature-dev-pipeline

Browse files
Files changed (2) hide show
  1. app.py +22 -13
  2. app_util.py +13 -19
app.py CHANGED
@@ -23,18 +23,28 @@ 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 +58,9 @@ 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 +77,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 +94,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/ai_dev",
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
+ print(f"identity: {identity}")
40
  if not identity:
41
+ identity = "pgdemo_dev"
42
+ ai = "stevez/ai_dev"
43
+ if identity in ais:
44
+ ai = ais[identity]
45
+ clouddisk = "pgsoft/clouddisk_dev"
46
+ if identity in clouddisks:
47
+ clouddisk = clouddisks[identity]
48
 
49
 
50
  def run(hf_token, service, game, functionality, nlp_command):
 
58
  user_name = "__fake__"
59
 
60
  # redirect all traffic to the proxy sever
61
+ global ai, clouddisk
62
  if redirect is not None:
63
+ ai = redirect
 
64
 
65
  if token is None or token == "":
66
  return "please specify hf token"
 
77
  service_start = beijing()
78
  print(f"<<<<<<<<<<<<<< service starts at {service_start} <<<<<<<<<<<<<<")
79
  if service in ["download game", "upload game", "list games"]:
80
+ res = app_util.call_clouddisk(clouddisk, service, nlp_command, token)
81
  res = json.loads(res)
82
  if res["result"] is None:
83
  outp = {"status": "Failure"}
 
94
  game,
95
  functionality,
96
  nlp_command,
97
+ ai,
98
  token,
99
  )
100
  if isinstance(outp, str):
app_util.py CHANGED
@@ -32,25 +32,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
 
32
  print(f"calling logger ends at {calling_end}, costs {timecost:.2f}s")
33
 
34
 
35
+ def call_clouddisk(url: str, service, arg, hf_token) -> str | None:
36
  ##########################
37
  # upload or download game
38
  ##########################
39
+ try:
40
+ client = Client(
41
+ url,
42
+ hf_token=hf_token,
43
+ verbose=False,
44
+ )
45
+ res = client.predict(service, arg, api_name="/predict")
46
+ print(f"[call_clouddisk] {service} from {url} [OK]")
47
+ return res
48
+ except Exception as e:
49
+ print(f"[call_clouddisk] {type(e)}: {e}")
50
+ return None