Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -14,18 +14,24 @@ from trellis.pipelines import TrellisTextTo3DPipeline
|
|
14 |
from trellis.representations import Gaussian, MeshExtractResult
|
15 |
from trellis.utils import render_utils, postprocessing_utils
|
16 |
|
|
|
|
|
|
|
17 |
MAX_SEED = np.iinfo(np.int32).max
|
18 |
TMP_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tmp')
|
19 |
os.makedirs(TMP_DIR, exist_ok=True)
|
20 |
|
|
|
21 |
def start_session(req: gr.Request):
|
22 |
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
23 |
os.makedirs(user_dir, exist_ok=True)
|
24 |
|
|
|
25 |
def end_session(req: gr.Request):
|
26 |
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
27 |
shutil.rmtree(user_dir)
|
28 |
|
|
|
29 |
def pack_state(gs: Gaussian, mesh: MeshExtractResult) -> dict:
|
30 |
return {
|
31 |
'gaussian': {
|
@@ -42,6 +48,7 @@ def pack_state(gs: Gaussian, mesh: MeshExtractResult) -> dict:
|
|
42 |
},
|
43 |
}
|
44 |
|
|
|
45 |
def unpack_state(state: dict) -> Tuple[Gaussian, edict, str]:
|
46 |
gs = Gaussian(
|
47 |
aabb=state['gaussian']['aabb'],
|
@@ -64,6 +71,7 @@ def unpack_state(state: dict) -> Tuple[Gaussian, edict, str]:
|
|
64 |
|
65 |
return gs, mesh
|
66 |
|
|
|
67 |
def get_seed(randomize_seed: bool, seed: int) -> int:
|
68 |
return np.random.randint(0, MAX_SEED) if randomize_seed else seed
|
69 |
|
@@ -100,7 +108,7 @@ def text_to_3d(
|
|
100 |
torch.cuda.empty_cache()
|
101 |
return state, video_path
|
102 |
|
103 |
-
@spaces.GPU
|
104 |
def extract_glb(
|
105 |
state: dict,
|
106 |
mesh_simplify: float,
|
@@ -115,6 +123,16 @@ def extract_glb(
|
|
115 |
torch.cuda.empty_cache()
|
116 |
return glb_path, glb_path
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
with gr.Blocks(delete_cache=(600, 600)) as demo:
|
119 |
gr.Markdown("""
|
120 |
# UTPL - Conversi贸n de Texto a objetos 3D usando IA
|
|
|
14 |
from trellis.representations import Gaussian, MeshExtractResult
|
15 |
from trellis.utils import render_utils, postprocessing_utils
|
16 |
|
17 |
+
import traceback
|
18 |
+
import sys
|
19 |
+
|
20 |
MAX_SEED = np.iinfo(np.int32).max
|
21 |
TMP_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tmp')
|
22 |
os.makedirs(TMP_DIR, exist_ok=True)
|
23 |
|
24 |
+
|
25 |
def start_session(req: gr.Request):
|
26 |
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
27 |
os.makedirs(user_dir, exist_ok=True)
|
28 |
|
29 |
+
|
30 |
def end_session(req: gr.Request):
|
31 |
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
32 |
shutil.rmtree(user_dir)
|
33 |
|
34 |
+
|
35 |
def pack_state(gs: Gaussian, mesh: MeshExtractResult) -> dict:
|
36 |
return {
|
37 |
'gaussian': {
|
|
|
48 |
},
|
49 |
}
|
50 |
|
51 |
+
|
52 |
def unpack_state(state: dict) -> Tuple[Gaussian, edict, str]:
|
53 |
gs = Gaussian(
|
54 |
aabb=state['gaussian']['aabb'],
|
|
|
71 |
|
72 |
return gs, mesh
|
73 |
|
74 |
+
|
75 |
def get_seed(randomize_seed: bool, seed: int) -> int:
|
76 |
return np.random.randint(0, MAX_SEED) if randomize_seed else seed
|
77 |
|
|
|
108 |
torch.cuda.empty_cache()
|
109 |
return state, video_path
|
110 |
|
111 |
+
@spaces.GPU(duration=90)
|
112 |
def extract_glb(
|
113 |
state: dict,
|
114 |
mesh_simplify: float,
|
|
|
123 |
torch.cuda.empty_cache()
|
124 |
return glb_path, glb_path
|
125 |
|
126 |
+
|
127 |
+
@spaces.GPU
|
128 |
+
def extract_gaussian(state: dict, req: gr.Request) -> Tuple[str, str]:
|
129 |
+
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
130 |
+
gs, _ = unpack_state(state)
|
131 |
+
gaussian_path = os.path.join(user_dir, 'sample.ply')
|
132 |
+
gs.save_ply(gaussian_path)
|
133 |
+
torch.cuda.empty_cache()
|
134 |
+
return gaussian_path, gaussian_path
|
135 |
+
|
136 |
with gr.Blocks(delete_cache=(600, 600)) as demo:
|
137 |
gr.Markdown("""
|
138 |
# UTPL - Conversi贸n de Texto a objetos 3D usando IA
|