qbhf2 commited on
Commit
7066f7d
·
verified ·
1 Parent(s): 0292dea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -11
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import gradio as gr
2
- # from custom_utils.setup_env import run_setup_script
3
  import asyncio
4
  import os
5
  import subprocess
@@ -44,6 +43,37 @@ def organize_images_into_structure(source_folder, new_folder):
44
  destination_file = os.path.join(subfolder_path, file_name)
45
  shutil.copy(source_file, destination_file)
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  def update_submenu(clothing_type):
48
  if clothing_type == "Top":
49
  return (
@@ -80,17 +110,24 @@ def update_submenu(clothing_type):
80
  with gr.Blocks(title="3D Garment Generator", theme=gr.themes.Default(text_size="sm")) as demo:
81
  front_collar = gr.State()
82
  back_collar = gr.State()
83
- render_engine = gr.State()
84
 
85
  with gr.Row():
86
  # Левая колонка: рендер и кнопки
87
  with gr.Column(scale=3):
88
  viewer = gr.HTML(iframe_html, label="3D Рендер")
89
- start_sim = gr.Button("Запустить симуляцию",variant="primary",scale=2)
 
 
 
 
 
 
 
90
  with gr.Row():
91
  save_render_btn = gr.Button("Сохранить рендер")
92
  save_obj_btn = gr.Button("Сохранить OBJ")
93
- zip_file = gr.File(label="Download Zip File")
 
94
 
95
  # Правая колонка: загрузки и параметры
96
  with gr.Column(scale=1):
@@ -143,13 +180,26 @@ with gr.Blocks(title="3D Garment Generator", theme=gr.themes.Default(text_size="
143
  inputs=clothing_type_dropdown,
144
  outputs=[front_dropdown, back_dropdown]
145
  )
146
-
147
-
148
- def run_smpl():
149
- subprocess.run([
150
- "python3", "smpl_visualizer.py",
151
- "--model-path", "/Users/user/Downloads/SMPL/SMPL_julia/SMPL_FEMALE.npz"
152
- ])
 
 
 
 
 
 
 
 
 
 
 
 
 
153
 
154
  if __name__ == "__main__":
155
  smpl_thread = threading.Thread(target=run_smpl)
 
1
  import gradio as gr
 
2
  import asyncio
3
  import os
4
  import subprocess
 
43
  destination_file = os.path.join(subfolder_path, file_name)
44
  shutil.copy(source_file, destination_file)
45
 
46
+ smpl_thread = None
47
+ smpl_process = None
48
+
49
+ def run_smpl():
50
+ global smpl_process
51
+ # Запускаем процесс и храним ссылку на него
52
+ smpl_process = subprocess.Popen([
53
+ "python3", "smpl_visualizer.py",
54
+ "--model-path", "./SMPL_FEMALE.npz"
55
+ ])
56
+ smpl_process.wait() # Ждём завершения процесса
57
+
58
+ def stop_smpl():
59
+ global smpl_process
60
+ if smpl_process and smpl_process.poll() is None:
61
+ smpl_process.terminate() # Мягко завершить
62
+ try:
63
+ smpl_process.wait(timeout=1)
64
+ except subprocess.TimeoutExpired:
65
+ smpl_process.kill() # Форсированно убить, если не завершился
66
+ smpl_process = None
67
+
68
+ def clear_render():
69
+ global smpl_thread
70
+ stop_smpl()
71
+ if smpl_thread and smpl_thread.is_alive():
72
+ smpl_thread.join()
73
+ smpl_thread = threading.Thread(target=run_smpl, daemon=True)
74
+ smpl_thread.start()
75
+ return gr.skip()
76
+
77
  def update_submenu(clothing_type):
78
  if clothing_type == "Top":
79
  return (
 
110
  with gr.Blocks(title="3D Garment Generator", theme=gr.themes.Default(text_size="sm")) as demo:
111
  front_collar = gr.State()
112
  back_collar = gr.State()
 
113
 
114
  with gr.Row():
115
  # Левая колонка: рендер и кнопки
116
  with gr.Column(scale=3):
117
  viewer = gr.HTML(iframe_html, label="3D Рендер")
118
+ sim_button = gr.Button("Запустить симуляцию",variant="primary",
119
+ scale=2,inputs=[gr.State("GarmentCode/pattern_data_sim.py"),
120
+ gr.State("GarmentCode/configs/pattern_data_sim.json")],
121
+ )
122
+ fit_button = gr.Button("Запустить фитинг",variant="primary",
123
+ scale=2,inputs=[gr.State("GarmentCode/pattern_fitter.py"),
124
+ gr.State("GarmentCode/configs/pattern_fitter.json")],
125
+ )
126
  with gr.Row():
127
  save_render_btn = gr.Button("Сохранить рендер")
128
  save_obj_btn = gr.Button("Сохранить OBJ")
129
+ clear_button = gr.Button("Очистить")
130
+ zip_file = gr.File(label="Download Zip File")
131
 
132
  # Правая колонка: загрузки и параметры
133
  with gr.Column(scale=1):
 
180
  inputs=clothing_type_dropdown,
181
  outputs=[front_dropdown, back_dropdown]
182
  )
183
+ ## Button callbacks ##
184
+ sim_button.click(
185
+ fn=run_simulation,
186
+ inputs=[gr.State("GarmentCode/pattern_data_sim.py"), gr.State("GarmentCode/configs/pattern_data_sim.json")],
187
+ outputs=viewer
188
+ )
189
+ fit_button.click(
190
+ fn=run_fitting,
191
+ inputs=[gr.State("GarmentCode/pattern_fitter.py"), gr.State("GarmentCode/configs/pattern_fitter.json")],
192
+ outputs=viewer
193
+ )
194
+ clear_button.click(
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)