Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| # from custom_utils.setup_env import run_setup_script | |
| import asyncio | |
| import os | |
| import subprocess | |
| import shutil | |
| import threading | |
| iframe_html = """ | |
| <iframe src="http://localhost:8080" width="100%" height="500" style="border:none;"></iframe> | |
| """ | |
| async def start_smpl(): | |
| proc = await asyncio.create_subprocess_exec("python", "smpl_visualizer.py") | |
| # Можно добавить логику ожидания запуска | |
| await proc.wait() | |
| return proc | |
| def organize_images_into_structure(source_folder, new_folder): | |
| os.makedirs(new_folder, exist_ok=True) | |
| for file_name in os.listdir(source_folder): | |
| source_file = os.path.join(source_folder, file_name) | |
| if os.path.isfile(source_file) and file_name.lower().endswith(('.png', '.jpg', '.jpeg')): | |
| folder_name = os.path.splitext(file_name)[0] | |
| subfolder_path = os.path.join(new_folder, folder_name, "outputs") | |
| os.makedirs(subfolder_path, exist_ok=True) | |
| destination_file = os.path.join(subfolder_path, file_name) | |
| shutil.copy(source_file, destination_file) | |
| 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=3): | |
| viewer = gr.HTML(iframe_html, label="3D Рендер") | |
| with gr.Row(): | |
| save_render_btn = gr.Button("Сохранить рендер") | |
| save_obj_btn = gr.Button("Сохранить OBJ") | |
| zip_file = gr.File(label="Download Zip File") | |
| # Правая колонка: загрузки и параметры | |
| with gr.Column(scale=1): | |
| gr.Markdown("### Параметры генерации") | |
| with gr.Row(): | |
| pattern_upload = gr.File( | |
| label="1. Лекала (JSON/SVG)", | |
| file_types=[".json", ".svg"], | |
| height=120 | |
| ) | |
| body_upload = gr.File( | |
| label="2. Тело (OBJ/GLB/GLTF/FBX)", | |
| file_types=[".obj", ".glb", ".gltf", ".fbx"], | |
| height=120 | |
| ) | |
| with gr.Row(): | |
| pattern_specs = gr.File( | |
| label="3.Спецификация (JSON/YAML)", | |
| file_types=[".json", ".yaml"], | |
| height=120 | |
| ) | |
| 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] | |
| ) | |
| def run_smpl(): | |
| subprocess.run([ | |
| "python3", "custom_utils/smpl_visualizer.py", | |
| "--model-path", "custom_utils/SMPL_FEMALE.npz" | |
| ]) | |
| if __name__ == "__main__": | |
| smpl_thread = threading.Thread(target=run_smpl) | |
| smpl_thread.start() | |
| demo.launch(share=True) | |