1
This commit is contained in:
6
.idea/ai_debugger.xml
generated
Normal file
6
.idea/ai_debugger.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AI Debugger Settings">
|
||||
<option name="importsOfInterestPresent" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
17
server.py
17
server.py
@@ -17,7 +17,7 @@ from minio import Minio
|
||||
from glb2svg import glb_to_obj, obj_to_step, step_to_svg
|
||||
from trellis.pipelines import TrellisImageTo3DPipeline
|
||||
from trellis.utils import render_utils, postprocessing_utils
|
||||
from utils.new_oss_client import MINIO_URL, MINIO_ACCESS, MINIO_SECRET, MINIO_SECURE, minio_get_image, MINIO_BUCKET, upload_bytes, upload_local_file, download_from_minio
|
||||
from utils.new_oss_client import MINIO_URL, MINIO_ACCESS, MINIO_SECRET, MINIO_SECURE, minio_get_image, upload_local_file, download_from_minio
|
||||
|
||||
minio_client = Minio(MINIO_URL, access_key=MINIO_ACCESS, secret_key=MINIO_SECRET, secure=MINIO_SECURE)
|
||||
|
||||
@@ -347,11 +347,12 @@ class ModelToThreeViews(ls.LitAPI):
|
||||
def setup(self, device):
|
||||
pass
|
||||
|
||||
def upload_local_file(self, local_path, type):
|
||||
def upload_local_file(self, local_path, type, bucket_name, user_id):
|
||||
"""
|
||||
通用上传函数:支持 SVG, PNG, OBJ 等
|
||||
"""
|
||||
object_name = f"3d_result/{type}/{uuid.uuid4().hex}.{type}"
|
||||
|
||||
object_name = f"{user_id}/3d_result/{type}/{uuid.uuid4().hex}.{type}"
|
||||
if not os.path.exists(local_path):
|
||||
print(f"错误: 文件 {local_path} 不存在")
|
||||
return None
|
||||
@@ -364,19 +365,21 @@ class ModelToThreeViews(ls.LitAPI):
|
||||
|
||||
try:
|
||||
minio_client.fput_object(
|
||||
bucket_name=MINIO_BUCKET,
|
||||
bucket_name=bucket_name,
|
||||
object_name=object_name,
|
||||
file_path=local_path,
|
||||
content_type=content_type
|
||||
)
|
||||
print(f"成功上传 [{content_type}]: {object_name}")
|
||||
return f"{MINIO_BUCKET}/{object_name}"
|
||||
return f"{bucket_name}/{object_name}"
|
||||
except Exception as e:
|
||||
print(f"上传失败: {e}")
|
||||
return None
|
||||
|
||||
def predict(self, request):
|
||||
minio_glb_path = request['minio_glb_path']
|
||||
bucket_name = request["bucket_name"]
|
||||
user_id = request["user_id"]
|
||||
|
||||
work_dir = f"glb_to_obj"
|
||||
os.makedirs(work_dir, exist_ok=True)
|
||||
@@ -425,7 +428,7 @@ class ModelToThreeViews(ls.LitAPI):
|
||||
print("=" * 10)
|
||||
|
||||
# 5 上传
|
||||
minio_svg_path = self.upload_local_file(combined_png, "svg")
|
||||
minio_svg_path = self.upload_local_file(combined_png, "svg", bucket_name, user_id)
|
||||
|
||||
return {"minio_svg_path": minio_svg_path}
|
||||
|
||||
@@ -436,4 +439,4 @@ if __name__ == "__main__":
|
||||
server = ls.LitServer([
|
||||
trellis_api,
|
||||
model_to_three_api])
|
||||
server.run(port=8120)
|
||||
server.run(port=8122)
|
||||
|
||||
Reference in New Issue
Block a user