Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,56 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from custom_utils.setup_env import run_setup_script
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
smpl_visualizer.run()
|
| 6 |
|
| 7 |
iframe_html = """
|
| 8 |
<iframe src="http://localhost:8080" width="100%" height="500" style="border:none;"></iframe>
|
| 9 |
"""
|
| 10 |
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def update_submenu(clothing_type):
|
| 13 |
"""Функция для динамического обновления подменю в зависимости от типа одежды."""
|
| 14 |
if clothing_type == "Top":
|
| 15 |
return (
|
| 16 |
-
gr.Dropdown.update(visible=True, label="Front Collar",
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
gr.Dropdown.update(visible=True, label="Back Collar",
|
| 20 |
-
|
| 21 |
-
|
| 22 |
)
|
| 23 |
elif clothing_type == "Down":
|
| 24 |
return (
|
| 25 |
-
gr.Dropdown.update(visible=True, label="Waist Style",
|
| 26 |
-
|
| 27 |
gr.Dropdown.update(visible=False)
|
| 28 |
)
|
| 29 |
elif clothing_type == "Full body":
|
| 30 |
return (
|
| 31 |
-
gr.Dropdown.update(visible=True, label="Overall Style",
|
| 32 |
-
|
| 33 |
gr.Dropdown.update(visible=False)
|
| 34 |
)
|
| 35 |
else:
|
|
@@ -39,109 +60,79 @@ def update_submenu(clothing_type):
|
|
| 39 |
)
|
| 40 |
|
| 41 |
with gr.Blocks(title="3D Garment Generator", theme=gr.themes.Default(text_size="sm")) as demo:
|
| 42 |
-
# Состояния для хранения выбранных значений
|
| 43 |
front_collar = gr.State()
|
| 44 |
back_collar = gr.State()
|
| 45 |
render_engine = gr.State()
|
| 46 |
-
|
| 47 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
with gr.Column(scale=1):
|
| 49 |
gr.Markdown("### Параметры генерации")
|
| 50 |
-
|
| 51 |
with gr.Row():
|
| 52 |
pattern_upload = gr.File(
|
| 53 |
label="1. Лекала (JSON/SVG)",
|
| 54 |
-
file_types=[".json", ".svg"]
|
|
|
|
|
|
|
| 55 |
)
|
| 56 |
body_upload = gr.File(
|
| 57 |
label="2. Тело (OBJ/GLB/GLTF/FBX)",
|
| 58 |
-
file_types=[".obj", ".glb", ".gltf", ".fbx"]
|
|
|
|
| 59 |
)
|
| 60 |
with gr.Row():
|
| 61 |
pattern_specs = gr.File(
|
| 62 |
label="3.Спецификация (JSON/YAML)",
|
| 63 |
-
file_types=[".json",".yaml"]
|
|
|
|
| 64 |
)
|
| 65 |
-
|
| 66 |
-
with gr.Row():
|
| 67 |
-
with gr.Column(scale=1):
|
| 68 |
with gr.Accordion("4. Параметры генерации", open=True):
|
| 69 |
-
# Выбор типа одежды
|
| 70 |
clothing_type_dropdown = gr.Dropdown(
|
| 71 |
label="Тип одежды",
|
| 72 |
choices=["Top", "Down", "Full body"],
|
| 73 |
value="Top",
|
| 74 |
interactive=True
|
| 75 |
)
|
| 76 |
-
|
| 77 |
-
# Подменю (изначально скрытое)
|
| 78 |
front_dropdown = gr.Dropdown(
|
| 79 |
visible=False,
|
| 80 |
label="Front Collar",
|
| 81 |
choices=[],
|
| 82 |
interactive=True
|
| 83 |
)
|
| 84 |
-
|
| 85 |
back_dropdown = gr.Dropdown(
|
| 86 |
visible=False,
|
| 87 |
label="Back Collar",
|
| 88 |
choices=[],
|
| 89 |
interactive=True
|
| 90 |
)
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
# Обновление подменю при изменении типа одежды
|
| 98 |
clothing_type_dropdown.change(
|
| 99 |
fn=update_submenu,
|
| 100 |
inputs=clothing_type_dropdown,
|
| 101 |
outputs=[front_dropdown, back_dropdown]
|
| 102 |
)
|
| 103 |
|
| 104 |
-
with gr.Accordion("5. Render engine", open=False):
|
| 105 |
-
render_radio = gr.Radio(
|
| 106 |
-
label="Движок рендеринга",
|
| 107 |
-
choices=["BPY", "Pyrender/Open3D", "Maya"],
|
| 108 |
-
value="Pyrender/Open3D"
|
| 109 |
-
)
|
| 110 |
-
|
| 111 |
-
with gr.Column(scale=3):
|
| 112 |
-
# viewer = gr.Model3D(label="3D Просмотрщик", interactive=True, height=500,
|
| 113 |
-
# clear_color=[255.0, 255.0, 255.0, 0.0]
|
| 114 |
-
# )
|
| 115 |
-
viewer = gr.HTML(iframe_html, label="3D Рендер")
|
| 116 |
-
with gr.Row():
|
| 117 |
-
save_render_btn = gr.Button("Сохранить рендер")
|
| 118 |
-
save_obj_btn = gr.Button("Сохранить OBJ")
|
| 119 |
-
|
| 120 |
-
# Обработчики событий
|
| 121 |
-
front_dropdown.change(
|
| 122 |
-
lambda x: x,
|
| 123 |
-
inputs=front_dropdown,
|
| 124 |
-
outputs=front_collar
|
| 125 |
-
)
|
| 126 |
-
|
| 127 |
-
back_dropdown.change(
|
| 128 |
-
lambda x: x,
|
| 129 |
-
inputs=back_dropdown,
|
| 130 |
-
outputs=back_collar
|
| 131 |
-
)
|
| 132 |
-
|
| 133 |
-
render_radio.change(
|
| 134 |
-
lambda x: x,
|
| 135 |
-
inputs=render_radio,
|
| 136 |
-
outputs=render_engine
|
| 137 |
-
)
|
| 138 |
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
)
|
| 144 |
|
| 145 |
if __name__ == "__main__":
|
| 146 |
-
|
| 147 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
# from custom_utils.setup_env import run_setup_script
|
| 3 |
+
import asyncio
|
| 4 |
+
import os
|
| 5 |
+
import subprocess
|
| 6 |
+
import shutil
|
| 7 |
+
import threading
|
| 8 |
|
|
|
|
| 9 |
|
| 10 |
iframe_html = """
|
| 11 |
<iframe src="http://localhost:8080" width="100%" height="500" style="border:none;"></iframe>
|
| 12 |
"""
|
| 13 |
|
| 14 |
|
| 15 |
+
|
| 16 |
+
async def start_smpl():
|
| 17 |
+
proc = await asyncio.create_subprocess_exec("python", "smpl_visualizer.py")
|
| 18 |
+
# Можно добавить логику ожидания запуска
|
| 19 |
+
await proc.wait()
|
| 20 |
+
return proc
|
| 21 |
+
|
| 22 |
+
def organize_images_into_structure(source_folder, new_folder):
|
| 23 |
+
os.makedirs(new_folder, exist_ok=True)
|
| 24 |
+
for file_name in os.listdir(source_folder):
|
| 25 |
+
source_file = os.path.join(source_folder, file_name)
|
| 26 |
+
if os.path.isfile(source_file) and file_name.lower().endswith(('.png', '.jpg', '.jpeg')):
|
| 27 |
+
folder_name = os.path.splitext(file_name)[0]
|
| 28 |
+
subfolder_path = os.path.join(new_folder, folder_name, "outputs")
|
| 29 |
+
os.makedirs(subfolder_path, exist_ok=True)
|
| 30 |
+
destination_file = os.path.join(subfolder_path, file_name)
|
| 31 |
+
shutil.copy(source_file, destination_file)
|
| 32 |
+
|
| 33 |
def update_submenu(clothing_type):
|
| 34 |
"""Функция для динамического обновления подменю в зависимости от типа одежды."""
|
| 35 |
if clothing_type == "Top":
|
| 36 |
return (
|
| 37 |
+
gr.Dropdown.update(visible=True, label="Front Collar",
|
| 38 |
+
choices=["CircleNeckHalf", "CurvyNeckHalf", "VNeckHalf", "SquareNeckHalf",
|
| 39 |
+
"TrapezoidNeckHalf", "CircleArcNeckHalf", "Bezier2NeckHalf"]),
|
| 40 |
+
gr.Dropdown.update(visible=True, label="Back Collar",
|
| 41 |
+
choices=["CircleNeckHalf", "CurvyNeckHalf", "VNeckHalf", "SquareNeckHalf",
|
| 42 |
+
"TrapezoidNeckHalf", "CircleArcNeckHalf", "Bezier2NeckHalf"])
|
| 43 |
)
|
| 44 |
elif clothing_type == "Down":
|
| 45 |
return (
|
| 46 |
+
gr.Dropdown.update(visible=True, label="Waist Style",
|
| 47 |
+
choices=["High Waist", "Low Waist", "Medium Waist"]),
|
| 48 |
gr.Dropdown.update(visible=False)
|
| 49 |
)
|
| 50 |
elif clothing_type == "Full body":
|
| 51 |
return (
|
| 52 |
+
gr.Dropdown.update(visible=True, label="Overall Style",
|
| 53 |
+
choices=["Slim Fit", "Loose Fit", "Regular Fit"]),
|
| 54 |
gr.Dropdown.update(visible=False)
|
| 55 |
)
|
| 56 |
else:
|
|
|
|
| 60 |
)
|
| 61 |
|
| 62 |
with gr.Blocks(title="3D Garment Generator", theme=gr.themes.Default(text_size="sm")) as demo:
|
|
|
|
| 63 |
front_collar = gr.State()
|
| 64 |
back_collar = gr.State()
|
| 65 |
render_engine = gr.State()
|
| 66 |
+
|
| 67 |
with gr.Row():
|
| 68 |
+
# Левая колонка: рендер и кнопки
|
| 69 |
+
with gr.Column(scale=3):
|
| 70 |
+
viewer = gr.HTML(iframe_html, label="3D Рендер")
|
| 71 |
+
with gr.Row():
|
| 72 |
+
save_render_btn = gr.Button("Сохранить рендер")
|
| 73 |
+
save_obj_btn = gr.Button("Сохранить OBJ")
|
| 74 |
+
zip_file = gr.File(label="Download Zip File")
|
| 75 |
+
|
| 76 |
+
# Правая колонка: загрузки и параметры
|
| 77 |
with gr.Column(scale=1):
|
| 78 |
gr.Markdown("### Параметры генерации")
|
|
|
|
| 79 |
with gr.Row():
|
| 80 |
pattern_upload = gr.File(
|
| 81 |
label="1. Лекала (JSON/SVG)",
|
| 82 |
+
file_types=[".json", ".svg"],
|
| 83 |
+
height=120
|
| 84 |
+
|
| 85 |
)
|
| 86 |
body_upload = gr.File(
|
| 87 |
label="2. Тело (OBJ/GLB/GLTF/FBX)",
|
| 88 |
+
file_types=[".obj", ".glb", ".gltf", ".fbx"],
|
| 89 |
+
height=120
|
| 90 |
)
|
| 91 |
with gr.Row():
|
| 92 |
pattern_specs = gr.File(
|
| 93 |
label="3.Спецификация (JSON/YAML)",
|
| 94 |
+
file_types=[".json", ".yaml"],
|
| 95 |
+
height=120
|
| 96 |
)
|
| 97 |
+
|
|
|
|
|
|
|
| 98 |
with gr.Accordion("4. Параметры генерации", open=True):
|
|
|
|
| 99 |
clothing_type_dropdown = gr.Dropdown(
|
| 100 |
label="Тип одежды",
|
| 101 |
choices=["Top", "Down", "Full body"],
|
| 102 |
value="Top",
|
| 103 |
interactive=True
|
| 104 |
)
|
|
|
|
|
|
|
| 105 |
front_dropdown = gr.Dropdown(
|
| 106 |
visible=False,
|
| 107 |
label="Front Collar",
|
| 108 |
choices=[],
|
| 109 |
interactive=True
|
| 110 |
)
|
|
|
|
| 111 |
back_dropdown = gr.Dropdown(
|
| 112 |
visible=False,
|
| 113 |
label="Back Collar",
|
| 114 |
choices=[],
|
| 115 |
interactive=True
|
| 116 |
)
|
| 117 |
+
overall_length = gr.Slider(
|
| 118 |
+
1, 50, value=25, label="Длина одежды",
|
| 119 |
+
info="Выберите значение от 1 до 50",
|
| 120 |
+
interactive=True
|
| 121 |
+
)
|
|
|
|
|
|
|
| 122 |
clothing_type_dropdown.change(
|
| 123 |
fn=update_submenu,
|
| 124 |
inputs=clothing_type_dropdown,
|
| 125 |
outputs=[front_dropdown, back_dropdown]
|
| 126 |
)
|
| 127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
+
def run_smpl():
|
| 130 |
+
subprocess.run([
|
| 131 |
+
"python3", "smpl_visualizer.py",
|
| 132 |
+
"--model-path", "/Users/user/Downloads/SMPL/SMPL_julia/SMPL_FEMALE.npz"
|
| 133 |
+
])
|
| 134 |
|
| 135 |
if __name__ == "__main__":
|
| 136 |
+
smpl_thread = threading.Thread(target=run_smpl)
|
| 137 |
+
smpl_thread.start()
|
| 138 |
+
demo.launch(share=True)
|