Spaces:
mashroo
/
Running on Zero

YoussefAnso commited on
Commit
953b294
·
1 Parent(s): 6a61ba8

Refactor Gradio interface to enhance input and output organization, update background choice label, and streamline button click event configuration for improved usability and clarity.

Browse files
Files changed (1) hide show
  1. app.py +42 -16
app.py CHANGED
@@ -223,47 +223,73 @@ with gr.Blocks(
223
  with gr.Column():
224
  input_image = gr.Image(
225
  label="Image input",
226
- image_mode="RGBA",
227
- sources="upload",
228
  type="pil",
 
229
  )
230
  bg_choice = gr.Radio(
231
- ["Alpha as mask", "Auto Remove background"],
232
  value="Auto Remove background",
233
- label="background choice"
234
  )
235
  fg_ratio = gr.Slider(
236
  label="Foreground Ratio",
237
  minimum=0.5,
238
  maximum=1.0,
239
  value=1.0,
240
- step=0.05,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  )
242
- bg_color = gr.ColorPicker(label="Background Color", value="#7F7F7F", interactive=False)
243
- seed_val = gr.Number(value=1234, label="seed", precision=0)
244
- guidance = gr.Number(value=5.5, minimum=3, maximum=10, label="guidance_scale")
245
- steps = gr.Number(value=30, minimum=30, maximum=100, label="sample steps", precision=0)
246
  generate_btn = gr.Button("Generate")
247
 
248
  with gr.Column():
249
- output_rgb = gr.Image(interactive=False, label="Output RGB image")
250
- output_ccm = gr.Image(interactive=False, label="Output CCM image")
251
- output_glb = gr.Model3D(label="Output GLB", interactive=False)
252
 
253
  # Connect the button click event
254
  generate_btn.click(
255
  fn=generate,
256
- inputs=[input_image, bg_choice, fg_ratio, bg_color, seed_val, guidance, steps],
 
 
 
 
 
 
 
 
257
  outputs=[output_rgb, output_ccm, output_glb],
258
- concurrency_limit=1
259
  )
260
 
261
  # Add examples without caching
262
  gr.Examples(
263
  examples=[[os.path.join("examples", i)] for i in os.listdir("examples")],
264
  inputs=input_image,
265
- cache_examples=False # Disable example caching
266
  )
267
 
268
  if __name__ == "__main__":
269
- demo.launch()
 
223
  with gr.Column():
224
  input_image = gr.Image(
225
  label="Image input",
 
 
226
  type="pil",
227
+ sources=["upload"]
228
  )
229
  bg_choice = gr.Radio(
230
+ choices=["Alpha as mask", "Auto Remove background"],
231
  value="Auto Remove background",
232
+ label="Background choice"
233
  )
234
  fg_ratio = gr.Slider(
235
  label="Foreground Ratio",
236
  minimum=0.5,
237
  maximum=1.0,
238
  value=1.0,
239
+ step=0.05
240
+ )
241
+ bg_color = gr.ColorPicker(
242
+ label="Background Color",
243
+ value="#7F7F7F",
244
+ interactive=False
245
+ )
246
+ seed_val = gr.Number(
247
+ value=1234,
248
+ label="Seed",
249
+ precision=0
250
+ )
251
+ guidance = gr.Number(
252
+ value=5.5,
253
+ minimum=3,
254
+ maximum=10,
255
+ label="Guidance scale"
256
+ )
257
+ steps = gr.Number(
258
+ value=30,
259
+ minimum=30,
260
+ maximum=100,
261
+ label="Sample steps",
262
+ precision=0
263
  )
 
 
 
 
264
  generate_btn = gr.Button("Generate")
265
 
266
  with gr.Column():
267
+ output_rgb = gr.Image(label="Output RGB image")
268
+ output_ccm = gr.Image(label="Output CCM image")
269
+ output_glb = gr.Model3D(label="Output GLB")
270
 
271
  # Connect the button click event
272
  generate_btn.click(
273
  fn=generate,
274
+ inputs=[
275
+ input_image,
276
+ bg_choice,
277
+ fg_ratio,
278
+ bg_color,
279
+ seed_val,
280
+ guidance,
281
+ steps
282
+ ],
283
  outputs=[output_rgb, output_ccm, output_glb],
284
+ api_name="predict"
285
  )
286
 
287
  # Add examples without caching
288
  gr.Examples(
289
  examples=[[os.path.join("examples", i)] for i in os.listdir("examples")],
290
  inputs=input_image,
291
+ cache_examples=False
292
  )
293
 
294
  if __name__ == "__main__":
295
+ demo.launch(show_api=True)