aiqtech commited on
Commit
3ff67eb
·
verified ·
1 Parent(s): 40669db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -29
app.py CHANGED
@@ -122,7 +122,9 @@ def preprocess_image(image: Image.Image) -> Tuple[str, Image.Image]:
122
  trial_id = str(uuid.uuid4())
123
  processed_image = g.trellis_pipeline.preprocess_image(image)
124
  if processed_image is not None:
125
- processed_image.save(f"{TMP_DIR}/{trial_id}.png")
 
 
126
  return trial_id, processed_image
127
  else:
128
  print("Error: Processed image is None")
@@ -173,7 +175,9 @@ def unpack_state(state: dict) -> Tuple[Gaussian, edict, str]:
173
 
174
  @spaces.GPU
175
  def image_to_3d(trial_id: str, seed: int, randomize_seed: bool, ss_guidance_strength: float, ss_sampling_steps: int, slat_guidance_strength: float, slat_sampling_steps: int) -> Tuple[dict, str]:
176
- if not trial_id: # trial_id 검증 추가
 
 
177
  print("Error: No trial_id provided")
178
  return None, None
179
 
@@ -182,11 +186,15 @@ def image_to_3d(trial_id: str, seed: int, randomize_seed: bool, ss_guidance_stre
182
  seed = np.random.randint(0, MAX_SEED)
183
 
184
  image_path = f"{TMP_DIR}/{trial_id}.png"
 
 
185
  if not os.path.exists(image_path):
186
  print(f"Error: Image file not found at {image_path}")
187
  return None, None
188
 
189
  image = Image.open(image_path)
 
 
190
 
191
  outputs = g.trellis_pipeline.run(
192
  image,
@@ -295,34 +303,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
295
  lines=3
296
  )
297
 
298
- # 이미지 프롬프트를 갤러리 전에 정의
299
  image_prompt = gr.Image(label="Image Prompt", image_mode="RGBA", type="pil", height=300)
300
 
301
- # Examples 갤러리를 image_prompt 아래로 이동
302
- if example_images:
303
- with gr.Row():
304
- gallery = gr.Gallery(
305
- value=example_images,
306
- label="Example Images",
307
- show_label=True,
308
- elem_id="gallery",
309
- columns=5,
310
- rows=5,
311
- height=200,
312
- allow_preview=True
313
- )
314
-
315
- # Gallery 클릭 이벤트 추가
316
- def load_example(evt: gr.SelectData):
317
- return example_images[evt.index]
318
-
319
- gallery.select(
320
- load_example,
321
- None,
322
- image_prompt,
323
- show_progress=True
324
- )
325
-
326
  with gr.Accordion("Image Generation Settings", open=False):
327
  with gr.Row():
328
  height = gr.Slider(
@@ -383,10 +366,37 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
383
  video_output = gr.Video(label="Generated 3D Asset", autoplay=True, loop=True, height=300)
384
  model_output = LitModel3D(label="Extracted GLB", exposure=20.0, height=300)
385
  download_glb = gr.DownloadButton(label="Download GLB", interactive=False)
386
-
387
  trial_id = gr.Textbox(visible=False)
388
  output_buf = gr.State()
389
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
390
  # Handlers
391
  generate_image_btn.click(
392
  text_to_image,
 
122
  trial_id = str(uuid.uuid4())
123
  processed_image = g.trellis_pipeline.preprocess_image(image)
124
  if processed_image is not None:
125
+ save_path = f"{TMP_DIR}/{trial_id}.png"
126
+ processed_image.save(save_path)
127
+ print(f"Saved processed image to: {save_path}")
128
  return trial_id, processed_image
129
  else:
130
  print("Error: Processed image is None")
 
175
 
176
  @spaces.GPU
177
  def image_to_3d(trial_id: str, seed: int, randomize_seed: bool, ss_guidance_strength: float, ss_sampling_steps: int, slat_guidance_strength: float, slat_sampling_steps: int) -> Tuple[dict, str]:
178
+ print(f"Starting image_to_3d with trial_id: {trial_id}")
179
+
180
+ if not trial_id or trial_id.strip() == "":
181
  print("Error: No trial_id provided")
182
  return None, None
183
 
 
186
  seed = np.random.randint(0, MAX_SEED)
187
 
188
  image_path = f"{TMP_DIR}/{trial_id}.png"
189
+ print(f"Looking for image at: {image_path}")
190
+
191
  if not os.path.exists(image_path):
192
  print(f"Error: Image file not found at {image_path}")
193
  return None, None
194
 
195
  image = Image.open(image_path)
196
+ print(f"Successfully loaded image with size: {image.size}")
197
+
198
 
199
  outputs = g.trellis_pipeline.run(
200
  image,
 
303
  lines=3
304
  )
305
 
306
+ # 이미지 프롬프트
307
  image_prompt = gr.Image(label="Image Prompt", image_mode="RGBA", type="pil", height=300)
308
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  with gr.Accordion("Image Generation Settings", open=False):
310
  with gr.Row():
311
  height = gr.Slider(
 
366
  video_output = gr.Video(label="Generated 3D Asset", autoplay=True, loop=True, height=300)
367
  model_output = LitModel3D(label="Extracted GLB", exposure=20.0, height=300)
368
  download_glb = gr.DownloadButton(label="Download GLB", interactive=False)
369
+
370
  trial_id = gr.Textbox(visible=False)
371
  output_buf = gr.State()
372
 
373
+ # Examples 갤러리를 맨 아래로 이동
374
+ if example_images:
375
+ gr.Markdown("""### Example Images""")
376
+ with gr.Row():
377
+ gallery = gr.Gallery(
378
+ value=example_images,
379
+ label="Click an image to use it",
380
+ show_label=True,
381
+ elem_id="gallery",
382
+ columns=5,
383
+ rows=5,
384
+ height=600,
385
+ allow_preview=True
386
+ )
387
+
388
+ def load_example(evt: gr.SelectData):
389
+ selected_image = Image.open(example_images[evt.index])
390
+ trial_id_val, processed_image = preprocess_image(selected_image)
391
+ return selected_image, trial_id_val
392
+
393
+ gallery.select(
394
+ load_example,
395
+ None,
396
+ [image_prompt, trial_id],
397
+ show_progress=True
398
+ )
399
+
400
  # Handlers
401
  generate_image_btn.click(
402
  text_to_image,