Spaces:
Sleeping
Sleeping
File size: 5,620 Bytes
99ffd02 658e8e1 c7e05f5 99ffd02 9185355 f4bae4d b651c81 f4bae4d b651c81 9185355 f4bae4d b651c81 f4bae4d 9185355 f4bae4d b651c81 f4bae4d 9185355 f4bae4d 97b4135 658e8e1 52df11a 76080a9 edfaaf0 658e8e1 50d2729 7de37b5 658e8e1 5141114 edfaaf0 1221c89 9185355 b651c81 9185355 658e8e1 9185355 129a798 9185355 658e8e1 129a798 9185355 658e8e1 9185355 129a798 9185355 658e8e1 129a798 b651c81 9185355 9409984 407f992 658e8e1 edfaaf0 b001341 edfaaf0 c7e05f5 8d4f5ae 658e8e1 76080a9 658e8e1 76080a9 b001341 76080a9 edfaaf0 76080a9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | import gradio as gr
from custom_utils.setup_env import run_setup_script
from custom_utils import smpl_visualizer
smpl_visualizer.run()
iframe_html = """
<iframe src="http://localhost:8080" width="100%" height="500" style="border:none;"></iframe>
"""
def update_submenu(clothing_type):
"""Функция для динамического обновления подменю в зависимости от типа одежды."""
if clothing_type == "Top":
return (
gr.Dropdown.update(visible=True, label="Front Collar",
choices=["CircleNeckHalf", "CurvyNeckHalf", "VNeckHalf", "SquareNeckHalf",
"TrapezoidNeckHalf", "CircleArcNeckHalf", "Bezier2NeckHalf"]),
gr.Dropdown.update(visible=True, label="Back Collar",
choices=["CircleNeckHalf", "CurvyNeckHalf", "VNeckHalf", "SquareNeckHalf",
"TrapezoidNeckHalf", "CircleArcNeckHalf", "Bezier2NeckHalf"])
)
elif clothing_type == "Down":
return (
gr.Dropdown.update(visible=True, label="Waist Style",
choices=["High Waist", "Low Waist", "Medium Waist"]),
gr.Dropdown.update(visible=False)
)
elif clothing_type == "Full body":
return (
gr.Dropdown.update(visible=True, label="Overall Style",
choices=["Slim Fit", "Loose Fit", "Regular Fit"]),
gr.Dropdown.update(visible=False)
)
else:
return (
gr.Dropdown.update(visible=False),
gr.Dropdown.update(visible=False)
)
with gr.Blocks(title="3D Garment Generator", theme=gr.themes.Default(text_size="sm")) as demo:
# Состояния для хранения выбранных значений
front_collar = gr.State()
back_collar = gr.State()
render_engine = gr.State()
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("### Параметры генерации")
with gr.Row():
pattern_upload = gr.File(
label="1. Лекала (JSON/SVG)",
file_types=[".json", ".svg"]
)
body_upload = gr.File(
label="2. Тело (OBJ/GLB/GLTF/FBX)",
file_types=[".obj", ".glb", ".gltf", ".fbx"]
)
with gr.Row():
pattern_specs = gr.File(
label="3.Спецификация (JSON/YAML)",
file_types=[".json",".yaml"]
)
with gr.Row():
with gr.Column(scale=1):
with gr.Accordion("4. Параметры генерации", open=True):
# Выбор типа одежды
clothing_type_dropdown = gr.Dropdown(
label="Тип одежды",
choices=["Top", "Down", "Full body"],
value="Top",
interactive=True
)
# Подменю (изначально скрытое)
front_dropdown = gr.Dropdown(
visible=False,
label="Front Collar",
choices=[],
interactive=True
)
back_dropdown = gr.Dropdown(
visible=False,
label="Back Collar",
choices=[],
interactive=True
)
# Общий параметр (должен быть после дропдаунов)
overall_length = gr.Slider(1, 50, value=25, label="Длина одежды",
info="Выберите значение от 1 до 50",
interactive=True)
# Обновление подменю при изменении типа одежды
clothing_type_dropdown.change(
fn=update_submenu,
inputs=clothing_type_dropdown,
outputs=[front_dropdown, back_dropdown]
)
with gr.Accordion("5. Render engine", open=False):
render_radio = gr.Radio(
label="Движок рендеринга",
choices=["BPY", "Pyrender/Open3D", "Maya"],
value="Pyrender/Open3D"
)
with gr.Column(scale=3):
# viewer = gr.Model3D(label="3D Просмотрщик", interactive=True, height=500,
# clear_color=[255.0, 255.0, 255.0, 0.0]
# )
viewer = gr.HTML(iframe_html, label="3D Рендер")
with gr.Row():
save_render_btn = gr.Button("Сохранить рендер")
save_obj_btn = gr.Button("Сохранить OBJ")
# Обработчики событий
front_dropdown.change(
lambda x: x,
inputs=front_dropdown,
outputs=front_collar
)
back_dropdown.change(
lambda x: x,
inputs=back_dropdown,
outputs=back_collar
)
render_radio.change(
lambda x: x,
inputs=render_radio,
outputs=render_engine
)
body_upload.change(
lambda file: file.name if file else None,
inputs=body_upload,
outputs=viewer
)
if __name__ == "__main__":
run_setup_script()
demo.launch()
|