Spaces:
mashroo
/
Running on Zero

YoussefAnso commited on
Commit
b492be8
·
1 Parent(s): 1eb08e4

Refactor Gradio interface by simplifying image input settings, streamlining background choice configuration, and enhancing output section layout for improved usability and clarity.

Browse files
Files changed (1) hide show
  1. app.py +12 -31
app.py CHANGED
@@ -215,29 +215,23 @@ with gr.Blocks() as demo:
215
  with gr.Row():
216
  image_input = gr.Image(
217
  label="Image input",
218
- image_mode="RGBA",
219
- sources=["upload"],
220
  type="pil"
221
  )
222
  processed_image = gr.Image(
223
  label="Processed Image",
224
- interactive=False,
225
- type="pil",
226
- image_mode="RGB"
227
  )
228
 
229
  with gr.Row():
230
  with gr.Column():
231
- with gr.Row():
232
- background_choice = gr.Radio(
233
- choices=["Alpha as mask", "Auto Remove background"],
234
- value="Auto Remove background",
235
- label="Background choice"
236
- )
237
  back_groud_color = gr.ColorPicker(
238
  label="Background Color",
239
- value="#7F7F7F",
240
- interactive=False
241
  )
242
  foreground_ratio = gr.Slider(
243
  label="Foreground Ratio",
@@ -271,34 +265,21 @@ with gr.Blocks() as demo:
271
 
272
  gr.Examples(
273
  examples=[[os.path.join("examples", i)] for i in os.listdir("examples")],
274
- inputs=[image_input],
275
- examples_per_page=20,
276
- cache_examples=False
277
  )
278
 
279
  with gr.Column():
280
- image_output = gr.Image(
281
- label="Output RGB image",
282
- interactive=False
283
- )
284
- xyz_output = gr.Image(
285
- label="Output CCM image",
286
- interactive=False
287
- )
288
- output_model = gr.Model3D(
289
- label="Output GLB",
290
- interactive=False
291
- )
292
  gr.Markdown("Note: Ensure that the input image is correctly pre-processed into a grey background, otherwise the results will be unpredictable.")
293
 
294
- # Define the processing chain
295
  def process_and_generate(image, bg_choice, fg_ratio, bg_color, seed_val, guidance, steps):
296
  if image is None:
297
  raise gr.Error("No image uploaded!")
298
  processed = preprocess_image(image, bg_choice, fg_ratio, bg_color)
299
  return gen_image(processed, seed_val, guidance, steps)
300
 
301
- # Connect the button click event with API endpoint
302
  text_button.click(
303
  fn=process_and_generate,
304
  inputs=[
@@ -319,4 +300,4 @@ with gr.Blocks() as demo:
319
  )
320
 
321
  if __name__ == "__main__":
322
- demo.queue().launch(show_api=True)
 
215
  with gr.Row():
216
  image_input = gr.Image(
217
  label="Image input",
 
 
218
  type="pil"
219
  )
220
  processed_image = gr.Image(
221
  label="Processed Image",
222
+ type="pil"
 
 
223
  )
224
 
225
  with gr.Row():
226
  with gr.Column():
227
+ background_choice = gr.Radio(
228
+ choices=["Alpha as mask", "Auto Remove background"],
229
+ value="Auto Remove background",
230
+ label="Background choice"
231
+ )
 
232
  back_groud_color = gr.ColorPicker(
233
  label="Background Color",
234
+ value="#7F7F7F"
 
235
  )
236
  foreground_ratio = gr.Slider(
237
  label="Foreground Ratio",
 
265
 
266
  gr.Examples(
267
  examples=[[os.path.join("examples", i)] for i in os.listdir("examples")],
268
+ inputs=[image_input]
 
 
269
  )
270
 
271
  with gr.Column():
272
+ image_output = gr.Image(label="Output RGB image")
273
+ xyz_output = gr.Image(label="Output CCM image")
274
+ output_model = gr.Model3D(label="Output GLB")
 
 
 
 
 
 
 
 
 
275
  gr.Markdown("Note: Ensure that the input image is correctly pre-processed into a grey background, otherwise the results will be unpredictable.")
276
 
 
277
  def process_and_generate(image, bg_choice, fg_ratio, bg_color, seed_val, guidance, steps):
278
  if image is None:
279
  raise gr.Error("No image uploaded!")
280
  processed = preprocess_image(image, bg_choice, fg_ratio, bg_color)
281
  return gen_image(processed, seed_val, guidance, steps)
282
 
 
283
  text_button.click(
284
  fn=process_and_generate,
285
  inputs=[
 
300
  )
301
 
302
  if __name__ == "__main__":
303
+ demo.queue().launch()