Ali Mohsin commited on
Commit
5e3538b
·
1 Parent(s): 4a2bd0c

added more changes

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +69 -8
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Garment3dKabeer
3
  emoji: 📊
4
  colorFrom: yellow
5
  colorTo: gray
 
1
  ---
2
+ title: Garment3d
3
  emoji: 📊
4
  colorFrom: yellow
5
  colorTo: gray
app.py CHANGED
@@ -126,16 +126,18 @@ DEFAULT_CONFIG = {
126
  'log_light_power': 3.0
127
  }
128
 
129
- def process_garment(input_type, text_prompt, base_text_prompt, target_image, base_image, custom_mesh, epochs, learning_rate, clip_weight, delta_clip_weight, progress=gr.Progress()):
130
  """
131
  Main function to process garment generation
132
 
133
  Args:
134
- input_type: Either "Text" or "Image" to determine the processing mode
135
  text_prompt: Text description of target garment (for text mode)
136
  base_text_prompt: Text description of base garment (for text mode)
137
  target_image: Image of target garment style (for image mode)
138
  base_image: Optional image of base garment (for image mode)
 
 
139
  custom_mesh: Optional custom source mesh file (.obj)
140
  epochs: Number of optimization epochs
141
  learning_rate: Optimization learning rate
@@ -150,7 +152,40 @@ def process_garment(input_type, text_prompt, base_text_prompt, target_image, bas
150
  config = DEFAULT_CONFIG.copy()
151
 
152
  # Set up input parameters based on mode
153
- if input_type == "Image" and target_image is not None:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  # Image-based processing
155
  progress(0.05, desc="Preparing image inputs...")
156
 
@@ -348,17 +383,18 @@ def create_interface():
348
  that can be used for virtual try-on applications.
349
 
350
  ## How to use:
351
- 1. Choose either **Text** or **Image** input mode using the radio button below
352
  2. For **Text** mode: Enter descriptions of your target and base garment styles
353
  3. For **Image** mode: Upload an image of your desired garment style
354
- 4. Click "Generate 3D Garment" to create your 3D mesh file
 
355
  """)
356
 
357
  with gr.Row():
358
  with gr.Column():
359
  # Input type selector
360
  input_type = gr.Radio(
361
- choices=["Text", "Image"],
362
  value="Text",
363
  label="Generation Method"
364
  )
@@ -395,6 +431,24 @@ def create_interface():
395
  )
396
  gr.Markdown("*Upload a base garment image (optional)*")
397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
398
  # Custom mesh
399
  custom_mesh = gr.File(
400
  label="Custom Source Mesh (Optional)",
@@ -448,6 +502,7 @@ def create_interface():
448
 
449
  - For text mode: Be specific in your descriptions
450
  - For image mode: Use clear, front-facing garment images
 
451
  - Higher epochs = better quality but longer processing time
452
  - Output files can be downloaded by clicking on them
453
 
@@ -461,16 +516,20 @@ def create_interface():
461
  def update_mode(mode):
462
  text_visibility = mode == "Text"
463
  image_visibility = mode == "Image"
 
464
  status_msg = f"Mode changed to {mode}. "
465
 
466
  if text_visibility:
467
  status_msg += "Enter garment descriptions and click Generate."
468
- else:
469
  status_msg += "Upload garment images and click Generate."
 
 
470
 
471
  return (
472
  gr.Group.update(visible=text_visibility),
473
  gr.Group.update(visible=image_visibility),
 
474
  status_msg
475
  )
476
 
@@ -491,7 +550,7 @@ def create_interface():
491
  input_type.change(
492
  fn=update_mode,
493
  inputs=[input_type],
494
- outputs=[text_group, image_group, status_output]
495
  )
496
 
497
  # Connect the button to the processing function with error handling
@@ -503,6 +562,8 @@ def create_interface():
503
  base_text_prompt,
504
  target_image,
505
  base_image,
 
 
506
  custom_mesh,
507
  epochs,
508
  learning_rate,
 
126
  'log_light_power': 3.0
127
  }
128
 
129
+ def process_garment(input_type, text_prompt, base_text_prompt, target_image, base_image, mesh_target_image, source_mesh_type, custom_mesh, epochs, learning_rate, clip_weight, delta_clip_weight, progress=gr.Progress()):
130
  """
131
  Main function to process garment generation
132
 
133
  Args:
134
+ input_type: Either "Text", "Image", or "Image to Mesh" to determine the processing mode
135
  text_prompt: Text description of target garment (for text mode)
136
  base_text_prompt: Text description of base garment (for text mode)
137
  target_image: Image of target garment style (for image mode)
138
  base_image: Optional image of base garment (for image mode)
139
+ mesh_target_image: Image for generating a 3D mesh (for image to mesh mode)
140
+ source_mesh_type: Type of source mesh to use as starting point (for image to mesh mode)
141
  custom_mesh: Optional custom source mesh file (.obj)
142
  epochs: Number of optimization epochs
143
  learning_rate: Optimization learning rate
 
152
  config = DEFAULT_CONFIG.copy()
153
 
154
  # Set up input parameters based on mode
155
+ if input_type == "Image to Mesh" and mesh_target_image is not None:
156
+ # Image-to-Mesh processing
157
+ progress(0.05, desc="Preparing mesh generation from image...")
158
+
159
+ # Save target image to temp directory
160
+ target_mesh_image_path = os.path.join(temp_dir, "target_mesh_image.jpg")
161
+
162
+ if isinstance(mesh_target_image, str):
163
+ shutil.copy(mesh_target_image, target_mesh_image_path)
164
+ elif isinstance(mesh_target_image, np.ndarray):
165
+ img = Image.fromarray(mesh_target_image.astype(np.uint8))
166
+ img.save(target_mesh_image_path)
167
+ elif hasattr(mesh_target_image, 'save'):
168
+ mesh_target_image.save(target_mesh_image_path)
169
+ else:
170
+ print(f"Unsupported image type: {type(mesh_target_image)}")
171
+ return None
172
+
173
+ print(f"Target mesh image saved to {target_mesh_image_path}")
174
+
175
+ # Set mesh paths based on selected source mesh type
176
+ source_mesh_file = f"./meshes/{source_mesh_type}.obj"
177
+
178
+ # Configure for image-to-mesh processing
179
+ config.update({
180
+ 'mesh': source_mesh_file,
181
+ 'image_prompt': target_mesh_image_path,
182
+ 'base_image_prompt': target_mesh_image_path, # Use same image as base
183
+ 'use_target_mesh': True,
184
+ 'fashion_image': True,
185
+ 'fashion_text': False,
186
+ })
187
+
188
+ elif input_type == "Image" and target_image is not None:
189
  # Image-based processing
190
  progress(0.05, desc="Preparing image inputs...")
191
 
 
383
  that can be used for virtual try-on applications.
384
 
385
  ## How to use:
386
+ 1. Choose **Text**, **Image**, or **Image to Mesh** input mode using the radio button below
387
  2. For **Text** mode: Enter descriptions of your target and base garment styles
388
  3. For **Image** mode: Upload an image of your desired garment style
389
+ 4. For **Image to Mesh** mode: Upload an image to generate a 3D mesh directly
390
+ 5. Click "Generate 3D Garment" to create your 3D mesh file
391
  """)
392
 
393
  with gr.Row():
394
  with gr.Column():
395
  # Input type selector
396
  input_type = gr.Radio(
397
+ choices=["Text", "Image", "Image to Mesh"],
398
  value="Text",
399
  label="Generation Method"
400
  )
 
431
  )
432
  gr.Markdown("*Upload a base garment image (optional)*")
433
 
434
+ # Image to Mesh inputs (hidden by default)
435
+ with gr.Group(visible=False) as image_to_mesh_group:
436
+ mesh_target_image = gr.Image(
437
+ label="Target Garment Image for Mesh Generation",
438
+ sources=["upload", "webcam"],
439
+ type="numpy",
440
+ interactive=True
441
+ )
442
+ gr.Markdown("*Upload an image of the garment to convert directly to a 3D mesh*")
443
+
444
+ source_mesh_type = gr.Dropdown(
445
+ label="Source Mesh Type",
446
+ choices=["t-shirt", "longsleeve", "tanktop", "poncho", "dress_shortsleeve"],
447
+ value="t-shirt",
448
+ interactive=True
449
+ )
450
+ gr.Markdown("*Select the type of base garment mesh to use as a starting point*")
451
+
452
  # Custom mesh
453
  custom_mesh = gr.File(
454
  label="Custom Source Mesh (Optional)",
 
502
 
503
  - For text mode: Be specific in your descriptions
504
  - For image mode: Use clear, front-facing garment images
505
+ - For image to mesh mode: Use clear garment images to generate a 3D mesh directly
506
  - Higher epochs = better quality but longer processing time
507
  - Output files can be downloaded by clicking on them
508
 
 
516
  def update_mode(mode):
517
  text_visibility = mode == "Text"
518
  image_visibility = mode == "Image"
519
+ image_to_mesh_visibility = mode == "Image to Mesh"
520
  status_msg = f"Mode changed to {mode}. "
521
 
522
  if text_visibility:
523
  status_msg += "Enter garment descriptions and click Generate."
524
+ elif image_visibility:
525
  status_msg += "Upload garment images and click Generate."
526
+ else:
527
+ status_msg += "Upload a garment image and select mesh type, then click Generate."
528
 
529
  return (
530
  gr.Group.update(visible=text_visibility),
531
  gr.Group.update(visible=image_visibility),
532
+ gr.Group.update(visible=image_to_mesh_visibility),
533
  status_msg
534
  )
535
 
 
550
  input_type.change(
551
  fn=update_mode,
552
  inputs=[input_type],
553
+ outputs=[text_group, image_group, image_to_mesh_group, status_output]
554
  )
555
 
556
  # Connect the button to the processing function with error handling
 
562
  base_text_prompt,
563
  target_image,
564
  base_image,
565
+ mesh_target_image,
566
+ source_mesh_type,
567
  custom_mesh,
568
  epochs,
569
  learning_rate,