ZhangYuhan commited on
Commit
e3c6dca
1 Parent(s): 8a2090e

update serve

Browse files
constants.py CHANGED
@@ -12,7 +12,7 @@ SERVER_PORT = os.getenv("SERVER_PORT", 7860)
12
  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", "https://tigerai.ca")
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
 
12
  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", None)
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
model/model_config.py CHANGED
@@ -56,11 +56,23 @@ register_model_config(
56
  online_model=False
57
  )
58
 
59
- # register_model_config(
60
- # model_name="wonder3d",
61
- # i2s_model=True,
62
- # online_model=False
63
- # )
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  register_model_config(
66
  model_name="lgm",
 
56
  online_model=False
57
  )
58
 
59
+ register_model_config(
60
+ model_name="sjc",
61
+ i2s_model=False,
62
+ online_model=False
63
+ )
64
+
65
+ register_model_config(
66
+ model_name="syncdreamer",
67
+ i2s_model=True,
68
+ online_model=False
69
+ )
70
+
71
+ register_model_config(
72
+ model_name="wonder3d",
73
+ i2s_model=True,
74
+ online_model=False
75
+ )
76
 
77
  register_model_config(
78
  model_name="lgm",
serve/controller.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import os
3
+ import time
4
+ import requests
5
+ import uvicorn
6
+ import numpy as np
7
+ from fastapi import FastAPI, Request
8
+
9
+ app = FastAPI()
10
+
11
+ if __name__ == "__main__":
12
+ parser = argparse.ArgumentParser()
13
+ parser.add_argument("--host", type=str, default="localhost")
14
+ parser.add_argument("--port", type=int, default=21001)
15
+ args = parser.parse_args()
16
+
17
+ uvicorn.run(app, host=args.host, port=args.port, log_level="info")
serve/log_server.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, File, UploadFile, Form, APIRouter
2
+ 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.
17
+ """
18
+ # Convert the string back to a JSON object (dict)
19
+ data = json.loads(json_str)
20
+ # Append the data to the specified file
21
+ os.makedirs(os.path.dirname(file_name), exist_ok=True)
22
+ async with aiofiles.open(file_name, mode='a') as f:
23
+ await f.write(json.dumps(data) + "\n")
24
+
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.
32
+ """
33
+ # Note: 'image_path' should include the file name and extension for the image to be saved.
34
+ os.makedirs(os.path.dirname(image_path), exist_ok=True)
35
+ async with aiofiles.open(image_path, mode='wb') as f:
36
+ content = await image.read() # Read the content of the uploaded image
37
+ await f.write(content) # Write the image content to a file
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.
45
+ """
46
+ # Ensure the directory for the log file exists
47
+ if os.path.dirname(log_path):
48
+ os.makedirs(os.path.dirname(log_path), exist_ok=True)
49
+
50
+ # Append the log message to the specified log file
51
+ async with aiofiles.open(log_path, mode='a') as f:
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}"}