ZhangYuhan commited on
Commit
716a927
1 Parent(s): 0f18427

update serve

Browse files
Files changed (3) hide show
  1. constants.py +1 -1
  2. serve/inference.py +1 -1
  3. serve/log_server.py +22 -5
constants.py CHANGED
@@ -13,7 +13,7 @@ ROOT_PATH = os.getenv("ROOT_PATH", None)
13
  ELO_RESULTS_DIR = os.getenv("ELO_RESULTS_DIR", "./arena_elo/results/latest")
14
 
15
  LOG_SERVER = os.getenv("LOG_SERVER", "http://2.0.0.1:8800")
16
- LOG_SERVER_SUBDOAMIN = os.getenv("LOG_SERVER_SUBDIR", "GenAI-Arena-hf-logs")
17
  LOG_SERVER_ADDR = os.getenv("LOG_SERVER_ADDR", f"{LOG_SERVER}/{LOG_SERVER_SUBDOAMIN}")
18
  # LOG SERVER API ENDPOINTS
19
  APPEND_JSON = "append_json"
 
13
  ELO_RESULTS_DIR = os.getenv("ELO_RESULTS_DIR", "./arena_elo/results/latest")
14
 
15
  LOG_SERVER = os.getenv("LOG_SERVER", "http://2.0.0.1:8800")
16
+ LOG_SERVER_SUBDOAMIN = os.getenv("LOG_SERVER_SUBDIR", "3DGen-Arena-hf-logs")
17
  LOG_SERVER_ADDR = os.getenv("LOG_SERVER_ADDR", f"{LOG_SERVER}/{LOG_SERVER_SUBDOAMIN}")
18
  # LOG SERVER API ENDPOINTS
19
  APPEND_JSON = "append_json"
serve/inference.py CHANGED
@@ -405,7 +405,7 @@ def generate_t2s_multi_annoy(gen_func, render_func,
405
  }
406
  else:
407
  start_time = time.time()
408
- shape_0, shape_1, model_name_0, model_name_1 = gen_func(text, model_name_0, model_name_1)
409
  generate_time = time.time() - start_time
410
 
411
  videos_0, videos_1 = render_func(shape_0, model_name_0, shape_1, model_name_1)
 
405
  }
406
  else:
407
  start_time = time.time()
408
+ shape_0, shape_1, model_name_0, model_name_1 = gen_func(text, model_name_0, model_name_1, i2s_mode=False)
409
  generate_time = time.time() - start_time
410
 
411
  videos_0, videos_1 = render_func(shape_0, model_name_0, shape_1, model_name_1)
serve/log_server.py CHANGED
@@ -3,14 +3,23 @@ from typing import Optional
3
  import json
4
  import os
5
  import aiofiles
 
 
 
 
6
  from log_utils import build_logger
7
  from constants import LOG_SERVER_SUBDOAMIN, APPEND_JSON, SAVE_IMAGE, SAVE_LOG
8
 
9
  logger = build_logger("log_server", "log_server.log", add_remote_handler=False)
10
 
11
- app = APIRouter(prefix=f"/{LOG_SERVER_SUBDOAMIN}")
 
 
 
 
 
12
 
13
- @app.post(f"/{APPEND_JSON}")
14
  async def append_json(json_str: str = Form(...), file_name: str = Form(...)):
15
  """
16
  Appends a JSON string to a specified file.
@@ -25,7 +34,7 @@ async def append_json(json_str: str = Form(...), file_name: str = Form(...)):
25
  logger.info(f"Appended 1 JSON object to {file_name}")
26
  return {"message": "JSON data appended successfully"}
27
 
28
- @app.post(f"/{SAVE_IMAGE}")
29
  async def save_image(image: UploadFile = File(...), image_path: str = Form(...)):
30
  """
31
  Saves an uploaded image to the specified path.
@@ -38,7 +47,7 @@ async def save_image(image: UploadFile = File(...), image_path: str = Form(...))
38
  logger.info(f"Image saved successfully at {image_path}")
39
  return {"message": f"Image saved successfully at {image_path}"}
40
 
41
- @app.post(f"/{SAVE_LOG}")
42
  async def save_log(message: str = Form(...), log_path: str = Form(...)):
43
  """
44
  Save a log message to a specified log file on the server.
@@ -52,4 +61,12 @@ async def save_log(message: str = Form(...), log_path: str = Form(...)):
52
  await f.write(f"{message}\n")
53
 
54
  logger.info(f"Romote log message saved to {log_path}")
55
- return {"message": f"Log message saved successfully to {log_path}"}
 
 
 
 
 
 
 
 
 
3
  import json
4
  import os
5
  import aiofiles
6
+
7
+ import sys
8
+ sys.path.append('..')
9
+
10
  from log_utils import build_logger
11
  from constants import LOG_SERVER_SUBDOAMIN, APPEND_JSON, SAVE_IMAGE, SAVE_LOG
12
 
13
  logger = build_logger("log_server", "log_server.log", add_remote_handler=False)
14
 
15
+ app = FastAPI()
16
+ router = APIRouter(prefix=f"/{LOG_SERVER_SUBDOAMIN}")
17
+
18
+ @router.get(f"/test")
19
+ async def test():
20
+ return "Successfully"
21
 
22
+ @router.post(f"/{APPEND_JSON}")
23
  async def append_json(json_str: str = Form(...), file_name: str = Form(...)):
24
  """
25
  Appends a JSON string to a specified file.
 
34
  logger.info(f"Appended 1 JSON object to {file_name}")
35
  return {"message": "JSON data appended successfully"}
36
 
37
+ @router.post(f"/{SAVE_IMAGE}")
38
  async def save_image(image: UploadFile = File(...), image_path: str = Form(...)):
39
  """
40
  Saves an uploaded image to the specified path.
 
47
  logger.info(f"Image saved successfully at {image_path}")
48
  return {"message": f"Image saved successfully at {image_path}"}
49
 
50
+ @router.post(f"/{SAVE_LOG}")
51
  async def save_log(message: str = Form(...), log_path: str = Form(...)):
52
  """
53
  Save a log message to a specified log file on the server.
 
61
  await f.write(f"{message}\n")
62
 
63
  logger.info(f"Romote log message saved to {log_path}")
64
+ return {"message": f"Log message saved successfully to {log_path}"}
65
+
66
+
67
+ app.include_router(router)
68
+
69
+ if __name__ == "__main__":
70
+ import uvicorn
71
+
72
+ uvicorn.run(app, host="127.0.0.1", port=8000)