Spaces:
mashroo
/
Running on Zero

YoussefAnso commited on
Commit
cc054b5
·
1 Parent(s): 1197127
Files changed (1) hide show
  1. app.py +26 -9
app.py CHANGED
@@ -212,7 +212,10 @@ with gr.Blocks() as demo:
212
  gr.Markdown("Note: Ensure that the input image is correctly pre-processed into a grey background, otherwise the results will be unpredictable.")
213
 
214
  inputs = [
215
- processed_image,
 
 
 
216
  seed,
217
  guidance_scale,
218
  step,
@@ -221,17 +224,31 @@ with gr.Blocks() as demo:
221
  image_output,
222
  xyz_ouput,
223
  output_model,
224
- # output_obj,
225
  ]
226
 
227
-
228
- text_button.click(fn=check_input_image, inputs=[image_input]).success(
229
- fn=preprocess_image,
230
- inputs=[image_input, background_choice, foreground_ratio, back_groud_color],
231
- outputs=[processed_image],
232
- ).success(
233
- fn=gen_image,
234
  inputs=inputs,
235
  outputs=outputs,
236
  )
 
237
  demo.queue().launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  gr.Markdown("Note: Ensure that the input image is correctly pre-processed into a grey background, otherwise the results will be unpredictable.")
213
 
214
  inputs = [
215
+ image_input,
216
+ background_choice,
217
+ foreground_ratio,
218
+ back_groud_color,
219
  seed,
220
  guidance_scale,
221
  step,
 
224
  image_output,
225
  xyz_ouput,
226
  output_model,
 
227
  ]
228
 
229
+ text_button.click(
230
+ fn=process_and_generate,
 
 
 
 
 
231
  inputs=inputs,
232
  outputs=outputs,
233
  )
234
+
235
  demo.queue().launch()
236
+
237
+ def process_and_generate(input_image, background_choice, foreground_ratio, backgroud_color, seed, scale, step):
238
+ """Process the input image and generate the 3D model in a single function"""
239
+ if input_image is None:
240
+ raise gr.Error("No image uploaded!")
241
+
242
+ # Preprocess the image
243
+ processed = preprocess_image(input_image, background_choice, foreground_ratio, backgroud_color)
244
+
245
+ # Generate the 3D model
246
+ pipeline.set_seed(seed)
247
+ rt_dict = pipeline(processed, scale=scale, step=step)
248
+ stage1_images = rt_dict["stage1_images"]
249
+ stage2_images = rt_dict["stage2_images"]
250
+ np_imgs = np.concatenate(stage1_images, 1)
251
+ np_xyzs = np.concatenate(stage2_images, 1)
252
+
253
+ glb_path = generate3d(model, np_imgs, np_xyzs, args.device)
254
+ return Image.fromarray(np_imgs), Image.fromarray(np_xyzs), glb_path