steveagi commited on
Commit
569ef51
·
unverified ·
2 Parent(s): 2c67f7c3db6cdc

Merge pull request #4 from east-and-west-magic/init-house-server

Browse files
Files changed (3) hide show
  1. app.py +4 -4
  2. app_util.py +25 -15
  3. call_pgai.py +1 -1
app.py CHANGED
@@ -15,7 +15,7 @@ from str_util import normalize_text
15
  #######################
16
  # proxy version
17
  #######################
18
- proxy_version = "1.0.0-2024-01-18-a" # reconstruct ai calling
19
 
20
  t = datetime.now()
21
  t = t.astimezone(ZoneInfo("Asia/Shanghai"))
@@ -117,12 +117,12 @@ demo = gr.Interface(
117
  info="Shared services",
118
  ),
119
  gr.Radio(
120
- ["watermelon"],
121
- value="watermelon",
122
  info="Which game you want the AI to support?",
123
  ),
124
  gr.Radio(
125
- functionality_list,
126
  value=functionality_list[0],
127
  # label = "What do you want to do?",
128
  info="What functionality?",
 
15
  #######################
16
  # proxy version
17
  #######################
18
+ proxy_version = "1.0.0-2024-05-14-a"
19
 
20
  t = datetime.now()
21
  t = t.astimezone(ZoneInfo("Asia/Shanghai"))
 
117
  info="Shared services",
118
  ),
119
  gr.Radio(
120
+ ["house"],
121
+ value="house",
122
  info="Which game you want the AI to support?",
123
  ),
124
  gr.Radio(
125
+ functionality_list[:1],
126
  value=functionality_list[0],
127
  # label = "What do you want to do?",
128
  info="What functionality?",
app_util.py CHANGED
@@ -37,22 +37,25 @@ def call_logger(log_info, caller, hf_token) -> None:
37
  print(f"calling logger ends at {calling_end}, costs {timecost:.2f}s")
38
 
39
 
40
- dataset_id = "pgsoft/watermelon"
41
- local_dir = "game"
42
- if not os.path.exists(local_dir):
43
- os.mkdir(local_dir)
 
 
44
  hf_api = HfApi()
45
 
46
 
47
  def file_service(service, arg: str, token: str):
48
  """download game, upload game, or list games"""
49
  if service == "download game":
50
- filepath = arg.strip() + ".json"
 
51
  res = download(
52
  dataset_id,
53
- filepath,
54
  repo_type="dataset",
55
- localdir=local_dir,
56
  token=token,
57
  )
58
  if not res:
@@ -92,9 +95,10 @@ def file_service(service, arg: str, token: str):
92
  maxtry = 5
93
  for retry in range(maxtry):
94
  md5code = md5(obj)
 
95
  if not hf_api.file_exists(
96
  repo_id=dataset_id,
97
- filename=md5code + ".json",
98
  repo_type="dataset",
99
  token=token,
100
  ):
@@ -102,22 +106,24 @@ def file_service(service, arg: str, token: str):
102
  sleep(0.1)
103
  obj["upload-time"] = beijing().__str__()
104
  maxtry -= 1
105
- filename = md5code + ".json"
106
  if not maxtry and hf_api.file_exists(
107
  repo_id=dataset_id,
108
- filename=md5code + ".json",
109
  repo_type="dataset",
110
  token=token,
111
  ):
112
  print(f"[{service}] error: file exists")
113
  return None
114
- localpath = os.sep.join([local_dir, filename])
 
 
 
115
  content = json.dumps(game, indent=4)
116
- with open(localpath, "w") as f:
117
  f.write(content)
118
  res = upload(
119
- localpath,
120
- filename,
121
  dataset_id,
122
  "dataset",
123
  token,
@@ -136,7 +142,11 @@ def file_service(service, arg: str, token: str):
136
  )
137
  if games is None:
138
  return None
139
- games = {item.split(".")[0]: item for item in games if len(item) >= 32}
 
 
 
 
140
  print(f"[{service}] OK")
141
  return games
142
  else:
 
37
  print(f"calling logger ends at {calling_end}, costs {timecost:.2f}s")
38
 
39
 
40
+ dataset_id = "pgsoft/game"
41
+ tempdir = "game"
42
+ gamename = "house"
43
+ localdir = os.path.join(tempdir, gamename)
44
+ if not os.path.exists(localdir):
45
+ os.makedirs(localdir)
46
  hf_api = HfApi()
47
 
48
 
49
  def file_service(service, arg: str, token: str):
50
  """download game, upload game, or list games"""
51
  if service == "download game":
52
+ filename = arg.strip() + ".json"
53
+ remotepath = "/".join(["house", filename[:2], filename])
54
  res = download(
55
  dataset_id,
56
+ remotepath=remotepath,
57
  repo_type="dataset",
58
+ localdir=tempdir,
59
  token=token,
60
  )
61
  if not res:
 
95
  maxtry = 5
96
  for retry in range(maxtry):
97
  md5code = md5(obj)
98
+ remotepath = "/".join([gamename, md5code[:2], md5code + ".json"])
99
  if not hf_api.file_exists(
100
  repo_id=dataset_id,
101
+ filename=remotepath,
102
  repo_type="dataset",
103
  token=token,
104
  ):
 
106
  sleep(0.1)
107
  obj["upload-time"] = beijing().__str__()
108
  maxtry -= 1
 
109
  if not maxtry and hf_api.file_exists(
110
  repo_id=dataset_id,
111
+ filename=remotepath,
112
  repo_type="dataset",
113
  token=token,
114
  ):
115
  print(f"[{service}] error: file exists")
116
  return None
117
+ filedir = os.path.join(localdir, md5code[:2])
118
+ if not os.path.exists(filedir):
119
+ os.mkdir(filedir)
120
+ filepath = os.path.join(filedir, md5code + ".json")
121
  content = json.dumps(game, indent=4)
122
+ with open(filepath, "w") as f:
123
  f.write(content)
124
  res = upload(
125
+ filepath,
126
+ remotepath,
127
  dataset_id,
128
  "dataset",
129
  token,
 
142
  )
143
  if games is None:
144
  return None
145
+ games = {
146
+ item.split(".")[0][-32:]: item
147
+ for item in games
148
+ if item.endswith(".json") and item.startswith("house")
149
+ }
150
  print(f"[{service}] OK")
151
  return games
152
  else:
call_pgai.py CHANGED
@@ -13,7 +13,7 @@ def post_to_pgai_helper(command: str) -> Any:
13
  }
14
 
15
  header = {'accept': 'application/json', 'Content-Type': 'application/json'}
16
- url_base = "https://steveagi-pgai.hf.space/games/watermelon/nlp"
17
  url_read = f"{url_base}/r"
18
 
19
  try:
 
13
  }
14
 
15
  header = {'accept': 'application/json', 'Content-Type': 'application/json'}
16
+ url_base = "https://steveagi-pgai.hf.space/games/house/nlp"
17
  url_read = f"{url_base}/r"
18
 
19
  try: