Spaces:
mashroo
/
Running on Zero

YoussefAnso commited on
Commit
3fe5f8a
·
1 Parent(s): 6d730d3

Refactor image generation process into a single API endpoint for improved clarity and efficiency

Browse files
Files changed (1) hide show
  1. app.py +26 -15
app.py CHANGED
@@ -256,22 +256,33 @@ with gr.Blocks(title="CRM: 3D Character Generation from Single Image") as demo:
256
  output_xyz = gr.Image(label="Generated XYZ", type="pil")
257
  output_glb = gr.Model3D(label="Generated 3D Model")
258
 
259
- # Connect the functions with explicit API names
 
 
 
 
 
 
 
 
 
260
  generate_btn.click(
261
- fn=check_input_image,
262
- inputs=[input_image],
263
- outputs=[input_image],
264
- api_name="check_input_image"
265
- ).success(
266
- fn=preprocess_image,
267
- inputs=[input_image, background_choice, foreground_ratio, back_groud_color],
268
- outputs=[processed_image],
269
- api_name="preprocess_image"
270
- ).success(
271
- fn=gen_image,
272
- inputs=[processed_image, seed, scale, step],
273
- outputs=[output_image, output_xyz, output_glb],
274
- api_name="gen_image"
 
 
275
  )
276
 
277
  # For Hugging Face Spaces, use minimal configuration
 
256
  output_xyz = gr.Image(label="Generated XYZ", type="pil")
257
  output_glb = gr.Model3D(label="Generated 3D Model")
258
 
259
+ def process_and_generate(input_image, background_choice, foreground_ratio, back_groud_color, seed, scale, step):
260
+ # First check input
261
+ input_image = check_input_image(input_image)
262
+ # Then preprocess
263
+ processed = preprocess_image(input_image, background_choice, foreground_ratio, back_groud_color)
264
+ # Finally generate
265
+ output_img, output_xyz_img, glb_path = gen_image(processed, seed, scale, step)
266
+ return processed, output_img, output_xyz_img, glb_path
267
+
268
+ # Connect the functions with a single API endpoint
269
  generate_btn.click(
270
+ fn=process_and_generate,
271
+ inputs=[
272
+ input_image,
273
+ background_choice,
274
+ foreground_ratio,
275
+ back_groud_color,
276
+ seed,
277
+ scale,
278
+ step
279
+ ],
280
+ outputs=[
281
+ processed_image,
282
+ output_image,
283
+ output_xyz,
284
+ output_glb
285
+ ]
286
  )
287
 
288
  # For Hugging Face Spaces, use minimal configuration