aiqtech commited on
Commit
e8095ff
·
verified ·
1 Parent(s): 0758696

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -1
app.py CHANGED
@@ -113,6 +113,12 @@ def preprocess_image(image: Image.Image) -> Tuple[str, Image.Image]:
113
  return "", None
114
 
115
  try:
 
 
 
 
 
 
116
  trial_id = str(uuid.uuid4())
117
  processed_image = g.trellis_pipeline.preprocess_image(image)
118
  if processed_image is not None:
@@ -253,10 +259,17 @@ def text_to_image(prompt: str, height: int, width: int, steps: int, scales: floa
253
  print(f"Error in image generation: {str(e)}")
254
  return None
255
 
256
- # Gradio Interface
257
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
258
  gr.Markdown("""## Craft3D""")
259
 
 
 
 
 
 
 
 
 
260
  with gr.Row():
261
  with gr.Column():
262
  text_prompt = gr.Textbox(
@@ -265,6 +278,20 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
265
  lines=3
266
  )
267
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
  with gr.Accordion("Image Generation Settings", open=False):
269
  with gr.Row():
270
  height = gr.Slider(
@@ -316,6 +343,16 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
316
  slat_sampling_steps = gr.Slider(1, 50, label="Latent Sampling Steps", value=12, step=1)
317
 
318
  generate_3d_btn = gr.Button("Generate 3D")
 
 
 
 
 
 
 
 
 
 
319
 
320
  with gr.Accordion("GLB Extraction Settings", open=False):
321
  mesh_simplify = gr.Slider(0.9, 0.98, label="Simplify", value=0.95, step=0.01)
 
113
  return "", None
114
 
115
  try:
116
+ # webp 이미지를 RGB로 변환
117
+ if isinstance(image, str) and image.endswith('.webp'):
118
+ image = Image.open(image).convert('RGB')
119
+ elif isinstance(image, Image.Image):
120
+ image = image.convert('RGB')
121
+
122
  trial_id = str(uuid.uuid4())
123
  processed_image = g.trellis_pipeline.preprocess_image(image)
124
  if processed_image is not None:
 
259
  print(f"Error in image generation: {str(e)}")
260
  return None
261
 
 
262
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
263
  gr.Markdown("""## Craft3D""")
264
 
265
+ # Examples 이미지 로드
266
+ example_dir = "assets/example_image/"
267
+ example_images = []
268
+ if os.path.exists(example_dir):
269
+ for file in os.listdir(example_dir):
270
+ if file.endswith('.webp'):
271
+ example_images.append(os.path.join(example_dir, file))
272
+
273
  with gr.Row():
274
  with gr.Column():
275
  text_prompt = gr.Textbox(
 
278
  lines=3
279
  )
280
 
281
+ # Examples 갤러리 추가
282
+ if example_images:
283
+ gr.Gallery(
284
+ value=example_images,
285
+ label="Example Images",
286
+ show_label=True,
287
+ elem_id="gallery",
288
+ columns=[3],
289
+ rows=[2],
290
+ height=200,
291
+ allow_preview=True
292
+ )
293
+
294
+
295
  with gr.Accordion("Image Generation Settings", open=False):
296
  with gr.Row():
297
  height = gr.Slider(
 
343
  slat_sampling_steps = gr.Slider(1, 50, label="Latent Sampling Steps", value=12, step=1)
344
 
345
  generate_3d_btn = gr.Button("Generate 3D")
346
+
347
+ gr.Examples(
348
+ examples=example_images,
349
+ inputs=image_prompt,
350
+ outputs=[trial_id, image_prompt],
351
+ fn=preprocess_image,
352
+ cache_examples=True,
353
+ label="Click on an example to load it"
354
+ )
355
+
356
 
357
  with gr.Accordion("GLB Extraction Settings", open=False):
358
  mesh_simplify = gr.Slider(0.9, 0.98, label="Simplify", value=0.95, step=0.01)