Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,8 @@ import shutil
|
|
| 6 |
import threading
|
| 7 |
from concurrent.futures import ThreadPoolExecutor
|
| 8 |
import logging
|
|
|
|
|
|
|
| 9 |
|
| 10 |
logging.basicConfig(level=logging.INFO)
|
| 11 |
|
|
@@ -13,6 +15,10 @@ logging.basicConfig(level=logging.INFO)
|
|
| 13 |
iframe_html = """
|
| 14 |
<iframe src="http://localhost:8080" width="100%" height="500" style="border:none;"></iframe>
|
| 15 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
async def run_simulation(data_path, config_path):
|
| 18 |
proc = await asyncio.create_subprocess_exec(
|
|
@@ -23,6 +29,33 @@ async def run_simulation(data_path, config_path):
|
|
| 23 |
await proc.wait() # дождаться завершения процесса
|
| 24 |
return
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
async def run_fitting(data_path, config_path):
|
| 27 |
proc = await asyncio.create_subprocess_exec(
|
| 28 |
"python3", "GarmentCode/pattern_fitter.py",
|
|
@@ -50,8 +83,8 @@ def run_smpl():
|
|
| 50 |
global smpl_process
|
| 51 |
# Запускаем процесс и храним ссылку на него
|
| 52 |
smpl_process = subprocess.Popen([
|
| 53 |
-
"python3", "
|
| 54 |
-
"--model-path", "
|
| 55 |
])
|
| 56 |
smpl_process.wait() # Ждём завершения процесса
|
| 57 |
|
|
@@ -115,13 +148,13 @@ with gr.Blocks(title="3D Garment Generator", theme=gr.themes.Default(text_size="
|
|
| 115 |
# Левая колонка: рендер и кнопки
|
| 116 |
with gr.Column(scale=3):
|
| 117 |
viewer = gr.HTML(iframe_html, label="3D Рендер")
|
| 118 |
-
sim_button = gr.Button("Запустить симуляцию",variant="primary",
|
| 119 |
-
|
| 120 |
-
|
| 121 |
)
|
| 122 |
-
fit_button = gr.Button("Запустить фитинг",variant="primary",
|
| 123 |
-
|
| 124 |
-
|
| 125 |
)
|
| 126 |
with gr.Row():
|
| 127 |
save_render_btn = gr.Button("Сохранить рендер")
|
|
@@ -139,19 +172,24 @@ with gr.Blocks(title="3D Garment Generator", theme=gr.themes.Default(text_size="
|
|
| 139 |
height=120
|
| 140 |
|
| 141 |
)
|
| 142 |
-
body_upload = gr.File(
|
| 143 |
-
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
height=120
|
| 146 |
)
|
| 147 |
with gr.Row():
|
| 148 |
-
|
| 149 |
-
label="
|
| 150 |
file_types=[".json", ".yaml"],
|
| 151 |
height=120
|
| 152 |
)
|
| 153 |
-
|
| 154 |
-
with gr.Accordion("4. Параметры генерации", open=True):
|
| 155 |
clothing_type_dropdown = gr.Dropdown(
|
| 156 |
label="Тип одежды",
|
| 157 |
choices=["Top", "Down", "Full body"],
|
|
@@ -182,8 +220,8 @@ with gr.Blocks(title="3D Garment Generator", theme=gr.themes.Default(text_size="
|
|
| 182 |
)
|
| 183 |
## Button callbacks ##
|
| 184 |
sim_button.click(
|
| 185 |
-
fn=
|
| 186 |
-
inputs=[
|
| 187 |
outputs=viewer
|
| 188 |
)
|
| 189 |
fit_button.click(
|
|
@@ -195,11 +233,6 @@ with gr.Blocks(title="3D Garment Generator", theme=gr.themes.Default(text_size="
|
|
| 195 |
fn=clear_render,
|
| 196 |
outputs=viewer
|
| 197 |
)
|
| 198 |
-
# def run_smpl():
|
| 199 |
-
# subprocess.run([
|
| 200 |
-
# "python3", "smpl_visualizer.py",
|
| 201 |
-
# "--model-path", "/Users/user/Downloads/SMPL/SMPL_julia/SMPL_FEMALE.npz"
|
| 202 |
-
# ])
|
| 203 |
|
| 204 |
if __name__ == "__main__":
|
| 205 |
smpl_thread = threading.Thread(target=run_smpl)
|
|
|
|
| 6 |
import threading
|
| 7 |
from concurrent.futures import ThreadPoolExecutor
|
| 8 |
import logging
|
| 9 |
+
import json
|
| 10 |
+
|
| 11 |
|
| 12 |
logging.basicConfig(level=logging.INFO)
|
| 13 |
|
|
|
|
| 15 |
iframe_html = """
|
| 16 |
<iframe src="http://localhost:8080" width="100%" height="500" style="border:none;"></iframe>
|
| 17 |
"""
|
| 18 |
+
DEFAULT_PATTERN_SPEC = "GarmentCode/assets/Patterns/shirt_mean_specification.json"
|
| 19 |
+
DEFAULT_SIM_CONFIG = "GarmentCode/assets/Sim_props/default_sim_props.yaml"
|
| 20 |
+
|
| 21 |
+
|
| 22 |
|
| 23 |
async def run_simulation(data_path, config_path):
|
| 24 |
proc = await asyncio.create_subprocess_exec(
|
|
|
|
| 29 |
await proc.wait() # дождаться завершения процесса
|
| 30 |
return
|
| 31 |
|
| 32 |
+
async def run_garment_sim(pattern_spec_file, sim_config_file):
|
| 33 |
+
pattern_path = getattr(pattern_spec_file, 'name', pattern_spec_file) if pattern_spec_file else DEFAULT_PATTERN_SPEC
|
| 34 |
+
config_path = getattr(sim_config_file, 'name', sim_config_file) if sim_config_file else DEFAULT_SIM_CONFIG
|
| 35 |
+
if not pattern_path or not config_path:
|
| 36 |
+
logging.critical(ValueError, "Не выбран файл спецификации паттерна или конфигурации симуляции.")
|
| 37 |
+
proc = await asyncio.create_subprocess_exec(
|
| 38 |
+
"python3", "GarmentCode/test_garment_sim.py",
|
| 39 |
+
"-p", pattern_path,
|
| 40 |
+
"-s", config_path,
|
| 41 |
+
stdout=asyncio.subprocess.PIPE,
|
| 42 |
+
stderr=asyncio.subprocess.PIPE
|
| 43 |
+
)
|
| 44 |
+
stdout, stderr = await proc.communicate()
|
| 45 |
+
if proc.returncode != 0:
|
| 46 |
+
print(stderr.decode())
|
| 47 |
+
raise RuntimeError("Simulation failed")
|
| 48 |
+
# Найти последнюю строку с JSON
|
| 49 |
+
lines = stdout.decode().splitlines()
|
| 50 |
+
for line in reversed(lines):
|
| 51 |
+
try:
|
| 52 |
+
result = json.loads(line)
|
| 53 |
+
return gr.Files(result["result_dir"])
|
| 54 |
+
except Exception:
|
| 55 |
+
continue
|
| 56 |
+
raise RuntimeError("Result path not found in output")
|
| 57 |
+
|
| 58 |
+
|
| 59 |
async def run_fitting(data_path, config_path):
|
| 60 |
proc = await asyncio.create_subprocess_exec(
|
| 61 |
"python3", "GarmentCode/pattern_fitter.py",
|
|
|
|
| 83 |
global smpl_process
|
| 84 |
# Запускаем процесс и храним ссылку на него
|
| 85 |
smpl_process = subprocess.Popen([
|
| 86 |
+
"python3", "smpl_visualizer.py",
|
| 87 |
+
"--model-path", "SMPL_FEMALE.npz"
|
| 88 |
])
|
| 89 |
smpl_process.wait() # Ждём завершения процесса
|
| 90 |
|
|
|
|
| 148 |
# Левая колонка: рендер и кнопки
|
| 149 |
with gr.Column(scale=3):
|
| 150 |
viewer = gr.HTML(iframe_html, label="3D Рендер")
|
| 151 |
+
sim_button = gr.Button("Запустить симуляцию",variant="primary",size="sm",
|
| 152 |
+
inputs=[gr.State("GarmentCode/pattern_data_sim.py"),
|
| 153 |
+
gr.State("GarmentCode/configs/pattern_data_sim.json")],
|
| 154 |
)
|
| 155 |
+
fit_button = gr.Button("Запустить фитинг",variant="primary",size="sm",
|
| 156 |
+
inputs=[gr.State("GarmentCode/pattern_fitter.py"),
|
| 157 |
+
gr.State("GarmentCode/configs/pattern_fitter.json")],
|
| 158 |
)
|
| 159 |
with gr.Row():
|
| 160 |
save_render_btn = gr.Button("Сохранить рендер")
|
|
|
|
| 172 |
height=120
|
| 173 |
|
| 174 |
)
|
| 175 |
+
# body_upload = gr.File(
|
| 176 |
+
# label="2. Тело (OBJ/GLB/GLTF/FBX)",
|
| 177 |
+
# file_types=[".obj", ".glb", ".gltf", ".fbx"],
|
| 178 |
+
# height=120
|
| 179 |
+
# )
|
| 180 |
+
with gr.Row():
|
| 181 |
+
pattern_specs = gr.File(
|
| 182 |
+
label="3. Спецификация паттерна (JSON/YAML)",
|
| 183 |
+
file_types=[".json", ".yaml"],
|
| 184 |
height=120
|
| 185 |
)
|
| 186 |
with gr.Row():
|
| 187 |
+
sim_config = gr.File(
|
| 188 |
+
label="4. Конфигурация симуляции (JSON/YAML)",
|
| 189 |
file_types=[".json", ".yaml"],
|
| 190 |
height=120
|
| 191 |
)
|
| 192 |
+
with gr.Accordion("5. Параметры генерации", open=True):
|
|
|
|
| 193 |
clothing_type_dropdown = gr.Dropdown(
|
| 194 |
label="Тип одежды",
|
| 195 |
choices=["Top", "Down", "Full body"],
|
|
|
|
| 220 |
)
|
| 221 |
## Button callbacks ##
|
| 222 |
sim_button.click(
|
| 223 |
+
fn=run_garment_sim,
|
| 224 |
+
inputs=[pattern_specs, sim_config],
|
| 225 |
outputs=viewer
|
| 226 |
)
|
| 227 |
fit_button.click(
|
|
|
|
| 233 |
fn=clear_render,
|
| 234 |
outputs=viewer
|
| 235 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
|
| 237 |
if __name__ == "__main__":
|
| 238 |
smpl_thread = threading.Thread(target=run_smpl)
|