Ali Mohsin commited on
Commit
63e7e53
Β·
1 Parent(s): e7860b2

update things

Browse files
Files changed (1) hide show
  1. app.py +97 -49
app.py CHANGED
@@ -125,48 +125,73 @@ apply_torchvision_fix()
125
 
126
  # Custom import handling for loop module to handle dependency issues
127
  loop = None
128
- try:
129
- # Try to import torchvision with error handling
 
 
 
 
130
  try:
131
- import torchvision
132
- print(f"torchvision {torchvision.__version__} imported successfully")
133
- except (RuntimeError, AttributeError) as e:
134
- if "operator torchvision::nms does not exist" in str(e) or "extension" in str(e):
135
- print("Detected torchvision compatibility issue. Applying additional fixes...")
136
- # Re-apply fixes after the error
137
- apply_torchvision_fix()
138
-
139
- # Try importing again with sys.modules manipulation
140
- try:
141
- if 'torchvision' in sys.modules:
142
- del sys.modules['torchvision']
143
- import torchvision
144
- print("torchvision imported successfully after fixes")
145
- except Exception as e2:
146
- print(f"torchvision still has issues, but continuing: {e2}")
147
- else:
148
- print(f"Other torchvision error: {e}")
149
 
150
- # Now try to import the loop module
151
- from loop import loop
152
- print("Successfully imported loop module")
153
- except ImportError as e:
154
- print(f"Error importing loop: {e}")
155
- print("Make sure all dependencies are installed correctly")
156
- if "torchvision" in str(e) or "torch" in str(e):
157
- print("This appears to be a PyTorch/torchvision compatibility issue.")
158
- print("The app will still start but may have limited functionality.")
159
- loop = None # Set to None so the app can still start
160
- except RuntimeError as e:
161
- print(f"Runtime error importing loop: {e}")
162
- if "operator torchvision::nms does not exist" in str(e):
163
- print("This is a known issue with incompatible PyTorch/torchvision versions.")
164
- print("Attempting to continue with limited functionality...")
165
- loop = None # Set to None so the app can still start
166
- except Exception as e:
167
- print(f"Unexpected error importing loop: {e}")
168
- print("The app will start with limited functionality.")
169
- loop = None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
  # Ensure NeuralJacobianFields is properly configured
172
  try:
@@ -281,7 +306,16 @@ def process_garment(input_type, text_prompt, base_text_prompt, mesh_target_image
281
  print(f"Target mesh image saved to {target_mesh_image_path}")
282
 
283
  # Set mesh paths based on selected source mesh type
284
- source_mesh_file = f"./meshes/{source_mesh_type}.obj"
 
 
 
 
 
 
 
 
 
285
 
286
  # Configure for image-to-mesh processing
287
  config.update({
@@ -349,7 +383,10 @@ def process_garment(input_type, text_prompt, base_text_prompt, mesh_target_image
349
  try:
350
  # Check if loop is available
351
  if loop is None:
352
- error_message = "Error: The garment generation engine could not be loaded due to dependency issues. This is likely due to compatibility issues between PyTorch and torchvision in the current environment."
 
 
 
353
  print(error_message)
354
  return error_message
355
 
@@ -481,18 +518,21 @@ def create_interface():
481
 
482
  # Image to Mesh inputs (hidden by default)
483
  with gr.Group(visible=False) as image_to_mesh_group:
 
484
  mesh_target_image = gr.Image(
485
  label="Target Garment Image for Mesh Generation",
486
- sources=["upload", "webcam"],
487
  type="numpy",
488
- interactive=True
 
489
  )
490
  gr.Markdown("*Upload an image of the garment to convert directly to a 3D mesh*")
491
 
 
492
  source_mesh_type = gr.Dropdown(
493
  label="Source Mesh Type",
494
- choices=["t-shirt", "longsleeve", "tanktop", "poncho", "dress_shortsleeve"],
495
- value="t-shirt",
496
  interactive=True
497
  )
498
  gr.Markdown("*Select the type of base garment mesh to use as a starting point*")
@@ -558,7 +598,15 @@ def create_interface():
558
  """)
559
 
560
  # Add a status output for errors and messages
561
- status_output = gr.Markdown("Ready to generate garments. Select an input method and click 'Generate 3D Garment'.")
 
 
 
 
 
 
 
 
562
 
563
  # Define a function to handle mode changes with clearer UI feedback
564
  def update_mode(mode):
@@ -572,8 +620,8 @@ def create_interface():
572
  status_msg += "Upload a garment image and select mesh type, then click Generate."
573
 
574
  return (
575
- gr.Group.update(visible=text_visibility),
576
- gr.Group.update(visible=image_to_mesh_visibility),
577
  status_msg
578
  )
579
 
 
125
 
126
  # Custom import handling for loop module to handle dependency issues
127
  loop = None
128
+ loop_import_error = None
129
+
130
+ def try_import_loop():
131
+ """Try to import the loop module with comprehensive error handling"""
132
+ global loop, loop_import_error
133
+
134
  try:
135
+ # Try to import torchvision with error handling
136
+ try:
137
+ import torchvision
138
+ print(f"torchvision {torchvision.__version__} imported successfully")
139
+ except (RuntimeError, AttributeError) as e:
140
+ if "operator torchvision::nms does not exist" in str(e) or "extension" in str(e):
141
+ print("Detected torchvision compatibility issue. Applying additional fixes...")
142
+ # Re-apply fixes after the error
143
+ apply_torchvision_fix()
 
 
 
 
 
 
 
 
 
144
 
145
+ # Try importing again with sys.modules manipulation
146
+ try:
147
+ if 'torchvision' in sys.modules:
148
+ del sys.modules['torchvision']
149
+ import torchvision
150
+ print("torchvision imported successfully after fixes")
151
+ except Exception as e2:
152
+ print(f"torchvision still has issues, but continuing: {e2}")
153
+ else:
154
+ print(f"Other torchvision error: {e}")
155
+
156
+ # Now try to import the loop module
157
+ from loop import loop as loop_func
158
+ loop = loop_func
159
+ print("Successfully imported loop module")
160
+ return True
161
+
162
+ except ImportError as e:
163
+ error_msg = f"ImportError: {e}"
164
+ print(error_msg)
165
+ if "torchvision" in str(e) or "torch" in str(e):
166
+ loop_import_error = "PyTorch/torchvision compatibility issue detected. The processing engine could not be loaded."
167
+ else:
168
+ loop_import_error = f"Missing dependencies: {str(e)}"
169
+ return False
170
+
171
+ except RuntimeError as e:
172
+ error_msg = f"RuntimeError: {e}"
173
+ print(error_msg)
174
+ if "operator torchvision::nms does not exist" in str(e):
175
+ loop_import_error = "PyTorch/torchvision version incompatibility. This is a known issue in some environments."
176
+ else:
177
+ loop_import_error = f"Runtime error during import: {str(e)}"
178
+ return False
179
+
180
+ except Exception as e:
181
+ error_msg = f"Unexpected error: {e}"
182
+ print(error_msg)
183
+ loop_import_error = f"Unexpected error during import: {str(e)}"
184
+ return False
185
+
186
+ # Try to import the loop module
187
+ print("Attempting to import processing engine...")
188
+ import_success = try_import_loop()
189
+
190
+ if import_success:
191
+ print("βœ“ Processing engine loaded successfully")
192
+ else:
193
+ print(f"βœ— Processing engine failed to load: {loop_import_error}")
194
+ print("The interface will still start, but processing functionality will be limited.")
195
 
196
  # Ensure NeuralJacobianFields is properly configured
197
  try:
 
306
  print(f"Target mesh image saved to {target_mesh_image_path}")
307
 
308
  # Set mesh paths based on selected source mesh type
309
+ # Map display names to actual file names
310
+ mesh_mapping = {
311
+ "tshirt": "tshirt",
312
+ "longsleeve": "longsleeve",
313
+ "tanktop": "tanktop",
314
+ "poncho": "poncho",
315
+ "dress_shortsleeve": "dress_shortsleeve"
316
+ }
317
+ mesh_file = mesh_mapping.get(source_mesh_type, "tshirt")
318
+ source_mesh_file = f"./meshes/{mesh_file}.obj"
319
 
320
  # Configure for image-to-mesh processing
321
  config.update({
 
383
  try:
384
  # Check if loop is available
385
  if loop is None:
386
+ if loop_import_error:
387
+ error_message = f"Error: {loop_import_error}"
388
+ else:
389
+ error_message = "Error: The garment generation engine could not be loaded due to dependency issues."
390
  print(error_message)
391
  return error_message
392
 
 
518
 
519
  # Image to Mesh inputs (hidden by default)
520
  with gr.Group(visible=False) as image_to_mesh_group:
521
+ gr.Markdown("### Upload Garment Image")
522
  mesh_target_image = gr.Image(
523
  label="Target Garment Image for Mesh Generation",
524
+ sources=["upload", "clipboard"],
525
  type="numpy",
526
+ interactive=True,
527
+ height=300
528
  )
529
  gr.Markdown("*Upload an image of the garment to convert directly to a 3D mesh*")
530
 
531
+ gr.Markdown("### Select Base Mesh Type")
532
  source_mesh_type = gr.Dropdown(
533
  label="Source Mesh Type",
534
+ choices=["tshirt", "longsleeve", "tanktop", "poncho", "dress_shortsleeve"],
535
+ value="tshirt",
536
  interactive=True
537
  )
538
  gr.Markdown("*Select the type of base garment mesh to use as a starting point*")
 
598
  """)
599
 
600
  # Add a status output for errors and messages
601
+ if loop is not None:
602
+ engine_status = "βœ… Processing engine loaded successfully"
603
+ status_msg = "Ready to generate garments. Select an input method and click 'Generate 3D Garment'."
604
+ else:
605
+ engine_status = f"❌ Processing engine unavailable: {loop_import_error or 'Unknown error'}"
606
+ status_msg = "Processing engine is currently unavailable. Please check the system status."
607
+
608
+ engine_status_output = gr.Markdown(f"**System Status:** {engine_status}")
609
+ status_output = gr.Markdown(status_msg)
610
 
611
  # Define a function to handle mode changes with clearer UI feedback
612
  def update_mode(mode):
 
620
  status_msg += "Upload a garment image and select mesh type, then click Generate."
621
 
622
  return (
623
+ gr.update(visible=text_visibility),
624
+ gr.update(visible=image_to_mesh_visibility),
625
  status_msg
626
  )
627