Spaces:
Running
on
Zero
Running
on
Zero
fix bug
Browse files- .gradio/certificate.pem +31 -0
- craftsman/__pycache__/__init__.cpython-310.pyc +0 -0
- craftsman/__pycache__/pipeline.cpython-310.pyc +0 -0
- craftsman/data/__pycache__/Objaverse.cpython-310.pyc +0 -0
- craftsman/data/__pycache__/__init__.cpython-310.pyc +0 -0
- craftsman/data/__pycache__/base.cpython-310.pyc +0 -0
- craftsman/models/__pycache__/__init__.cpython-310.pyc +0 -0
- craftsman/models/autoencoders/__pycache__/__init__.cpython-310.pyc +0 -0
- craftsman/models/autoencoders/__pycache__/michelangelo_autoencoder.cpython-310.pyc +0 -0
- craftsman/models/conditional_encoders/__pycache__/__init__.cpython-310.pyc +0 -0
- craftsman/models/conditional_encoders/__pycache__/base.cpython-310.pyc +0 -0
- craftsman/models/conditional_encoders/__pycache__/cond_encoder.cpython-310.pyc +0 -0
- craftsman/models/conditional_encoders/clip/__pycache__/modeling_clip.cpython-310.pyc +0 -0
- craftsman/models/conditional_encoders/clip/__pycache__/modeling_conditional_clip.cpython-310.pyc +0 -0
- craftsman/models/conditional_encoders/dino_v2/__pycache__/modeling_conditional_dinov2.cpython-310.pyc +0 -0
- craftsman/models/conditional_encoders/dino_v2/__pycache__/modeling_dinov2.cpython-310.pyc +0 -0
- craftsman/models/denoisers/__pycache__/__init__.cpython-310.pyc +0 -0
- craftsman/models/denoisers/__pycache__/pixart_denoiser.cpython-310.pyc +0 -0
- craftsman/models/denoisers/__pycache__/utils.cpython-310.pyc +0 -0
- craftsman/models/geometry/__pycache__/__init__.cpython-310.pyc +0 -0
- craftsman/models/geometry/__pycache__/base.cpython-310.pyc +0 -0
- craftsman/models/geometry/__pycache__/utils.cpython-310.pyc +0 -0
- craftsman/models/transformers/__pycache__/attention.cpython-310.pyc +0 -0
- craftsman/models/transformers/__pycache__/perceiver_1d.cpython-310.pyc +0 -0
- craftsman/models/transformers/__pycache__/utils.cpython-310.pyc +0 -0
- craftsman/systems/__pycache__/__init__.cpython-310.pyc +0 -0
- craftsman/systems/__pycache__/base.cpython-310.pyc +0 -0
- craftsman/systems/__pycache__/pixart_diffusion.cpython-310.pyc +0 -0
- craftsman/systems/__pycache__/shape_autoencoder.cpython-310.pyc +0 -0
- craftsman/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- craftsman/utils/__pycache__/base.cpython-310.pyc +0 -0
- craftsman/utils/__pycache__/checkpoint.cpython-310.pyc +0 -0
- craftsman/utils/__pycache__/config.cpython-310.pyc +0 -0
- craftsman/utils/__pycache__/misc.cpython-310.pyc +0 -0
- craftsman/utils/__pycache__/ops.cpython-310.pyc +0 -0
- craftsman/utils/__pycache__/saving.cpython-310.pyc +0 -0
- craftsman/utils/__pycache__/scheduler.cpython-310.pyc +0 -0
- craftsman/utils/__pycache__/typing.cpython-310.pyc +0 -0
- gradio_app.py +4 -4
- server.py +98 -0
.gradio/certificate.pem
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-----BEGIN CERTIFICATE-----
|
2 |
+
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
|
31 |
+
-----END CERTIFICATE-----
|
craftsman/__pycache__/__init__.cpython-310.pyc
CHANGED
Binary files a/craftsman/__pycache__/__init__.cpython-310.pyc and b/craftsman/__pycache__/__init__.cpython-310.pyc differ
|
|
craftsman/__pycache__/pipeline.cpython-310.pyc
CHANGED
Binary files a/craftsman/__pycache__/pipeline.cpython-310.pyc and b/craftsman/__pycache__/pipeline.cpython-310.pyc differ
|
|
craftsman/data/__pycache__/Objaverse.cpython-310.pyc
CHANGED
Binary files a/craftsman/data/__pycache__/Objaverse.cpython-310.pyc and b/craftsman/data/__pycache__/Objaverse.cpython-310.pyc differ
|
|
craftsman/data/__pycache__/__init__.cpython-310.pyc
CHANGED
Binary files a/craftsman/data/__pycache__/__init__.cpython-310.pyc and b/craftsman/data/__pycache__/__init__.cpython-310.pyc differ
|
|
craftsman/data/__pycache__/base.cpython-310.pyc
CHANGED
Binary files a/craftsman/data/__pycache__/base.cpython-310.pyc and b/craftsman/data/__pycache__/base.cpython-310.pyc differ
|
|
craftsman/models/__pycache__/__init__.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/__pycache__/__init__.cpython-310.pyc and b/craftsman/models/__pycache__/__init__.cpython-310.pyc differ
|
|
craftsman/models/autoencoders/__pycache__/__init__.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/autoencoders/__pycache__/__init__.cpython-310.pyc and b/craftsman/models/autoencoders/__pycache__/__init__.cpython-310.pyc differ
|
|
craftsman/models/autoencoders/__pycache__/michelangelo_autoencoder.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/autoencoders/__pycache__/michelangelo_autoencoder.cpython-310.pyc and b/craftsman/models/autoencoders/__pycache__/michelangelo_autoencoder.cpython-310.pyc differ
|
|
craftsman/models/conditional_encoders/__pycache__/__init__.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/conditional_encoders/__pycache__/__init__.cpython-310.pyc and b/craftsman/models/conditional_encoders/__pycache__/__init__.cpython-310.pyc differ
|
|
craftsman/models/conditional_encoders/__pycache__/base.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/conditional_encoders/__pycache__/base.cpython-310.pyc and b/craftsman/models/conditional_encoders/__pycache__/base.cpython-310.pyc differ
|
|
craftsman/models/conditional_encoders/__pycache__/cond_encoder.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/conditional_encoders/__pycache__/cond_encoder.cpython-310.pyc and b/craftsman/models/conditional_encoders/__pycache__/cond_encoder.cpython-310.pyc differ
|
|
craftsman/models/conditional_encoders/clip/__pycache__/modeling_clip.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/conditional_encoders/clip/__pycache__/modeling_clip.cpython-310.pyc and b/craftsman/models/conditional_encoders/clip/__pycache__/modeling_clip.cpython-310.pyc differ
|
|
craftsman/models/conditional_encoders/clip/__pycache__/modeling_conditional_clip.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/conditional_encoders/clip/__pycache__/modeling_conditional_clip.cpython-310.pyc and b/craftsman/models/conditional_encoders/clip/__pycache__/modeling_conditional_clip.cpython-310.pyc differ
|
|
craftsman/models/conditional_encoders/dino_v2/__pycache__/modeling_conditional_dinov2.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/conditional_encoders/dino_v2/__pycache__/modeling_conditional_dinov2.cpython-310.pyc and b/craftsman/models/conditional_encoders/dino_v2/__pycache__/modeling_conditional_dinov2.cpython-310.pyc differ
|
|
craftsman/models/conditional_encoders/dino_v2/__pycache__/modeling_dinov2.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/conditional_encoders/dino_v2/__pycache__/modeling_dinov2.cpython-310.pyc and b/craftsman/models/conditional_encoders/dino_v2/__pycache__/modeling_dinov2.cpython-310.pyc differ
|
|
craftsman/models/denoisers/__pycache__/__init__.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/denoisers/__pycache__/__init__.cpython-310.pyc and b/craftsman/models/denoisers/__pycache__/__init__.cpython-310.pyc differ
|
|
craftsman/models/denoisers/__pycache__/pixart_denoiser.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/denoisers/__pycache__/pixart_denoiser.cpython-310.pyc and b/craftsman/models/denoisers/__pycache__/pixart_denoiser.cpython-310.pyc differ
|
|
craftsman/models/denoisers/__pycache__/utils.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/denoisers/__pycache__/utils.cpython-310.pyc and b/craftsman/models/denoisers/__pycache__/utils.cpython-310.pyc differ
|
|
craftsman/models/geometry/__pycache__/__init__.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/geometry/__pycache__/__init__.cpython-310.pyc and b/craftsman/models/geometry/__pycache__/__init__.cpython-310.pyc differ
|
|
craftsman/models/geometry/__pycache__/base.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/geometry/__pycache__/base.cpython-310.pyc and b/craftsman/models/geometry/__pycache__/base.cpython-310.pyc differ
|
|
craftsman/models/geometry/__pycache__/utils.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/geometry/__pycache__/utils.cpython-310.pyc and b/craftsman/models/geometry/__pycache__/utils.cpython-310.pyc differ
|
|
craftsman/models/transformers/__pycache__/attention.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/transformers/__pycache__/attention.cpython-310.pyc and b/craftsman/models/transformers/__pycache__/attention.cpython-310.pyc differ
|
|
craftsman/models/transformers/__pycache__/perceiver_1d.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/transformers/__pycache__/perceiver_1d.cpython-310.pyc and b/craftsman/models/transformers/__pycache__/perceiver_1d.cpython-310.pyc differ
|
|
craftsman/models/transformers/__pycache__/utils.cpython-310.pyc
CHANGED
Binary files a/craftsman/models/transformers/__pycache__/utils.cpython-310.pyc and b/craftsman/models/transformers/__pycache__/utils.cpython-310.pyc differ
|
|
craftsman/systems/__pycache__/__init__.cpython-310.pyc
CHANGED
Binary files a/craftsman/systems/__pycache__/__init__.cpython-310.pyc and b/craftsman/systems/__pycache__/__init__.cpython-310.pyc differ
|
|
craftsman/systems/__pycache__/base.cpython-310.pyc
CHANGED
Binary files a/craftsman/systems/__pycache__/base.cpython-310.pyc and b/craftsman/systems/__pycache__/base.cpython-310.pyc differ
|
|
craftsman/systems/__pycache__/pixart_diffusion.cpython-310.pyc
CHANGED
Binary files a/craftsman/systems/__pycache__/pixart_diffusion.cpython-310.pyc and b/craftsman/systems/__pycache__/pixart_diffusion.cpython-310.pyc differ
|
|
craftsman/systems/__pycache__/shape_autoencoder.cpython-310.pyc
CHANGED
Binary files a/craftsman/systems/__pycache__/shape_autoencoder.cpython-310.pyc and b/craftsman/systems/__pycache__/shape_autoencoder.cpython-310.pyc differ
|
|
craftsman/utils/__pycache__/__init__.cpython-310.pyc
CHANGED
Binary files a/craftsman/utils/__pycache__/__init__.cpython-310.pyc and b/craftsman/utils/__pycache__/__init__.cpython-310.pyc differ
|
|
craftsman/utils/__pycache__/base.cpython-310.pyc
CHANGED
Binary files a/craftsman/utils/__pycache__/base.cpython-310.pyc and b/craftsman/utils/__pycache__/base.cpython-310.pyc differ
|
|
craftsman/utils/__pycache__/checkpoint.cpython-310.pyc
CHANGED
Binary files a/craftsman/utils/__pycache__/checkpoint.cpython-310.pyc and b/craftsman/utils/__pycache__/checkpoint.cpython-310.pyc differ
|
|
craftsman/utils/__pycache__/config.cpython-310.pyc
CHANGED
Binary files a/craftsman/utils/__pycache__/config.cpython-310.pyc and b/craftsman/utils/__pycache__/config.cpython-310.pyc differ
|
|
craftsman/utils/__pycache__/misc.cpython-310.pyc
CHANGED
Binary files a/craftsman/utils/__pycache__/misc.cpython-310.pyc and b/craftsman/utils/__pycache__/misc.cpython-310.pyc differ
|
|
craftsman/utils/__pycache__/ops.cpython-310.pyc
CHANGED
Binary files a/craftsman/utils/__pycache__/ops.cpython-310.pyc and b/craftsman/utils/__pycache__/ops.cpython-310.pyc differ
|
|
craftsman/utils/__pycache__/saving.cpython-310.pyc
CHANGED
Binary files a/craftsman/utils/__pycache__/saving.cpython-310.pyc and b/craftsman/utils/__pycache__/saving.cpython-310.pyc differ
|
|
craftsman/utils/__pycache__/scheduler.cpython-310.pyc
CHANGED
Binary files a/craftsman/utils/__pycache__/scheduler.cpython-310.pyc and b/craftsman/utils/__pycache__/scheduler.cpython-310.pyc differ
|
|
craftsman/utils/__pycache__/typing.cpython-310.pyc
CHANGED
Binary files a/craftsman/utils/__pycache__/typing.cpython-310.pyc and b/craftsman/utils/__pycache__/typing.cpython-310.pyc differ
|
|
gradio_app.py
CHANGED
@@ -141,7 +141,7 @@ def image2mesh(image: Any,
|
|
141 |
steps: int = 50,
|
142 |
seed: int = 4,
|
143 |
target_face_count: int = 2000,
|
144 |
-
octree_depth: int =
|
145 |
|
146 |
# global rmbg
|
147 |
# processed_image = rmbg.run(rm_type, image, foreground_ratio, background_choice)
|
@@ -186,7 +186,8 @@ def image2mesh(image: Any,
|
|
186 |
def mesh2texture(mesh_file, image_file):
|
187 |
headers = {'Content-Type': 'application/json'}
|
188 |
# server_url = "114.249.238.184:34119"
|
189 |
-
server_url = "algodemo.sz.lightions.top:31025"
|
|
|
190 |
with open(image_file, 'rb') as f:
|
191 |
image_bytes = f.read()
|
192 |
with open(mesh_file, 'rb') as f:
|
@@ -263,7 +264,6 @@ if __name__=="__main__":
|
|
263 |
with gr.Row():
|
264 |
image_input = gr.Image(
|
265 |
label="Image Input",
|
266 |
-
image_mode="RGBA",
|
267 |
sources="upload",
|
268 |
type="filepath",
|
269 |
)
|
@@ -289,7 +289,7 @@ if __name__=="__main__":
|
|
289 |
|
290 |
with gr.Row():
|
291 |
scheduler = gr.Dropdown(label="scheluder", value="DDIMScheduler",choices=list(scheluder_dict.keys()))
|
292 |
-
octree_depth = gr.Slider(label="Octree Depth", value=
|
293 |
|
294 |
with gr.Row():
|
295 |
gr.Examples(
|
|
|
141 |
steps: int = 50,
|
142 |
seed: int = 4,
|
143 |
target_face_count: int = 2000,
|
144 |
+
octree_depth: int = 8):
|
145 |
|
146 |
# global rmbg
|
147 |
# processed_image = rmbg.run(rm_type, image, foreground_ratio, background_choice)
|
|
|
186 |
def mesh2texture(mesh_file, image_file):
|
187 |
headers = {'Content-Type': 'application/json'}
|
188 |
# server_url = "114.249.238.184:34119"
|
189 |
+
# server_url = "algodemo.sz.lightions.top:31025"
|
190 |
+
server_url = "algodemo.sz.lightions.top:31024"
|
191 |
with open(image_file, 'rb') as f:
|
192 |
image_bytes = f.read()
|
193 |
with open(mesh_file, 'rb') as f:
|
|
|
264 |
with gr.Row():
|
265 |
image_input = gr.Image(
|
266 |
label="Image Input",
|
|
|
267 |
sources="upload",
|
268 |
type="filepath",
|
269 |
)
|
|
|
289 |
|
290 |
with gr.Row():
|
291 |
scheduler = gr.Dropdown(label="scheluder", value="DDIMScheduler",choices=list(scheluder_dict.keys()))
|
292 |
+
octree_depth = gr.Slider(label="Octree Depth", value=8, minimum=4, maximum=9, step=1)
|
293 |
|
294 |
with gr.Row():
|
295 |
gr.Examples(
|
server.py
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
import base64
|
3 |
+
import os
|
4 |
+
from datetime import datetime
|
5 |
+
import traceback
|
6 |
+
import trimesh
|
7 |
+
import torch
|
8 |
+
from craftsman import CraftsManPipeline
|
9 |
+
|
10 |
+
CURRENT_DIR = f'/tmp/native3d_server/{os.getpid()}'
|
11 |
+
os.makedirs(CURRENT_DIR, exist_ok=True)
|
12 |
+
|
13 |
+
def parse_parameters():
|
14 |
+
parser = argparse.ArgumentParser("native3d")
|
15 |
+
parser.add_argument('--host', default="0.0.0.0", type=str)
|
16 |
+
parser.add_argument('--port', default=12345, type=int)
|
17 |
+
return parser.parse_args()
|
18 |
+
|
19 |
+
# -------------------- fastapi --------------------
|
20 |
+
from typing import Optional
|
21 |
+
from pydantic import BaseModel, Field
|
22 |
+
|
23 |
+
class Native3DRequestV1(BaseModel):
|
24 |
+
image_path: str # input image path
|
25 |
+
mesh_path: str # output mesh path, support glb or obj in clean dir
|
26 |
+
|
27 |
+
class Native3DResponseV1(BaseModel):
|
28 |
+
pass
|
29 |
+
|
30 |
+
class Native3DRequestV2(BaseModel):
|
31 |
+
image_bytes: str # input image bytes(base64)
|
32 |
+
mesh_type: str # output mesh type, support glb or obj
|
33 |
+
|
34 |
+
class Native3DResponseV2(BaseModel):
|
35 |
+
mesh_bytes: str # output mesh bytes(base64)
|
36 |
+
|
37 |
+
if __name__=="__main__":
|
38 |
+
parse_args = parse_parameters()
|
39 |
+
|
40 |
+
# prepare models
|
41 |
+
pipeline = CraftsManPipeline.from_pretrained("/home/super/Desktop/8TDisk/weiyu/CraftsMan_gradio/ckpts/craftsman-v1-5", device="cuda:0", torch_dtype=torch.float32)
|
42 |
+
|
43 |
+
# -------------------- fastapi --------------------
|
44 |
+
from fastapi import FastAPI, Request
|
45 |
+
import requests
|
46 |
+
app = FastAPI()
|
47 |
+
|
48 |
+
@app.post("/native3d_v1", response_model=Native3DResponseV1)
|
49 |
+
async def native3d(request: Request, image_to_mesh_request: Native3DRequestV1):
|
50 |
+
try:
|
51 |
+
print(f"image_to_mesh_request = {image_to_mesh_request}")
|
52 |
+
mesh = pipeline(image_to_mesh_request.image_path).meshes[0]
|
53 |
+
os.makedirs(os.path.dirname(os.path.abspath(image_to_mesh_request.mesh_path)), exist_ok=True)
|
54 |
+
mesh.export(image_to_mesh_request.mesh_path)
|
55 |
+
except Exception as e:
|
56 |
+
traceback.print_exc()
|
57 |
+
print(f"generate_model error: {e}")
|
58 |
+
return Native3DResponseV1()
|
59 |
+
|
60 |
+
@app.post("/native3d_v2", response_model=Native3DResponseV2)
|
61 |
+
async def native3d(request: Request, image_to_mesh_request: Native3DRequestV2):
|
62 |
+
try:
|
63 |
+
# print(f"image_to_mesh_request = {image_to_mesh_request}")
|
64 |
+
mesh_type = image_to_mesh_request.mesh_type
|
65 |
+
assert mesh_type in ['obj', 'glb']
|
66 |
+
task_id = datetime.now().strftime('%Y-%m-%d-%H-%M-%S-%f') + '-' + 'native3d'
|
67 |
+
current_dir = os.path.join(CURRENT_DIR, task_id)
|
68 |
+
os.makedirs(current_dir, exist_ok=True)
|
69 |
+
image_path = os.path.join(current_dir, 'input_image.png')
|
70 |
+
with open(image_path, 'wb') as f:
|
71 |
+
f.write(base64.b64decode(image_to_mesh_request.image_bytes))
|
72 |
+
mesh_path = os.path.join(current_dir, f'output_mesh.{mesh_type}')
|
73 |
+
import time
|
74 |
+
start = time.time()
|
75 |
+
# mesh = pipeline(image_path).meshes[0]
|
76 |
+
# mesh = pipeline(image_path, mc_depth=7, num_inference_steps=50).meshes[0]
|
77 |
+
mesh = pipeline(image_path).meshes[0]
|
78 |
+
print(f"Time: {time.time() - start}s")
|
79 |
+
os.makedirs(os.path.dirname(os.path.abspath(mesh_path)), exist_ok=True)
|
80 |
+
mesh.visual = trimesh.visual.TextureVisuals(
|
81 |
+
material=trimesh.visual.material.PBRMaterial(
|
82 |
+
baseColorFactor=(255, 255, 255), main_color=(255, 255, 255), metallicFactor=0.05, roughnessFactor=1.0
|
83 |
+
)
|
84 |
+
)
|
85 |
+
mesh.export(mesh_path)
|
86 |
+
with open(mesh_path, 'rb') as f:
|
87 |
+
mesh_bytes = f.read()
|
88 |
+
except Exception as e:
|
89 |
+
traceback.print_exc()
|
90 |
+
print(f"generate_model error: {e}")
|
91 |
+
return Native3DResponseV2(mesh_bytes=base64.b64encode(mesh_bytes).decode('utf-8'))
|
92 |
+
|
93 |
+
@app.get("/health")
|
94 |
+
async def health():
|
95 |
+
return {"status": "OK"}
|
96 |
+
|
97 |
+
import uvicorn
|
98 |
+
uvicorn.run(app, host=parse_args.host, port=parse_args.port)
|