Spaces:
mashroo
/
Running on Zero

YoussefAnso commited on
Commit
dbc79a8
·
1 Parent(s): e98b019

Refactor Gradio interface to utilize Blocks for improved layout and organization, enhancing user interaction with dedicated input and output sections while maintaining minimal launch settings.

Browse files
Files changed (1) hide show
  1. app.py +57 -44
app.py CHANGED
@@ -212,48 +212,61 @@ def generate(image, bg_choice, fg_ratio, bg_color, seed_val, guidance, steps):
212
  processed = preprocess_image(image, bg_choice, fg_ratio, bg_color)
213
  return gen_image(processed, seed_val, guidance, steps)
214
 
215
- # Create a simple Interface instead of Blocks
216
- demo = gr.Interface(
217
- fn=generate,
218
- inputs=[
219
- gr.Image(
220
- label="Image input",
221
- image_mode="RGBA",
222
- sources="upload",
223
- type="pil",
224
- ),
225
- gr.Radio(
226
- ["Alpha as mask", "Auto Remove background"],
227
- value="Auto Remove background",
228
- label="background choice"
229
- ),
230
- gr.Slider(
231
- label="Foreground Ratio",
232
- minimum=0.5,
233
- maximum=1.0,
234
- value=1.0,
235
- step=0.05,
236
- ),
237
- gr.ColorPicker(label="Background Color", value="#7F7F7F", interactive=False),
238
- gr.Number(value=1234, label="seed", precision=0),
239
- gr.Number(value=5.5, minimum=3, maximum=10, label="guidance_scale"),
240
- gr.Number(value=30, minimum=30, maximum=100, label="sample steps", precision=0)
241
- ],
242
- outputs=[
243
- gr.Image(interactive=False, label="Output RGB image"),
244
- gr.Image(interactive=False, label="Output CCM image"),
245
- gr.Model3D(label="Output GLB", interactive=False)
246
- ],
247
- title="CRM: Single Image to 3D Textured Mesh with Convolutional Reconstruction Model",
248
- description=_DESCRIPTION,
249
- examples=[[os.path.join("examples", i)] for i in os.listdir("examples")],
250
- concurrency_limit=1,
251
- analytics_enabled=False
252
- )
 
 
 
 
 
 
 
 
 
 
 
253
 
254
- # Launch with minimal parameters
255
- demo.launch(
256
- server_name="0.0.0.0",
257
- server_port=7860,
258
- show_error=True
259
- )
 
 
 
212
  processed = preprocess_image(image, bg_choice, fg_ratio, bg_color)
213
  return gen_image(processed, seed_val, guidance, steps)
214
 
215
+ # Create a Blocks interface
216
+ with gr.Blocks(analytics_enabled=False) as demo:
217
+ gr.Markdown("# CRM: Single Image to 3D Textured Mesh with Convolutional Reconstruction Model")
218
+ gr.Markdown(_DESCRIPTION)
219
+
220
+ with gr.Row():
221
+ with gr.Column():
222
+ input_image = gr.Image(
223
+ label="Image input",
224
+ image_mode="RGBA",
225
+ sources="upload",
226
+ type="pil",
227
+ )
228
+ bg_choice = gr.Radio(
229
+ ["Alpha as mask", "Auto Remove background"],
230
+ value="Auto Remove background",
231
+ label="background choice"
232
+ )
233
+ fg_ratio = gr.Slider(
234
+ label="Foreground Ratio",
235
+ minimum=0.5,
236
+ maximum=1.0,
237
+ value=1.0,
238
+ step=0.05,
239
+ )
240
+ bg_color = gr.ColorPicker(label="Background Color", value="#7F7F7F", interactive=False)
241
+ seed_val = gr.Number(value=1234, label="seed", precision=0)
242
+ guidance = gr.Number(value=5.5, minimum=3, maximum=10, label="guidance_scale")
243
+ steps = gr.Number(value=30, minimum=30, maximum=100, label="sample steps", precision=0)
244
+ generate_btn = gr.Button("Generate")
245
+
246
+ with gr.Column():
247
+ output_rgb = gr.Image(interactive=False, label="Output RGB image")
248
+ output_ccm = gr.Image(interactive=False, label="Output CCM image")
249
+ output_glb = gr.Model3D(label="Output GLB", interactive=False)
250
+
251
+ # Connect the button click event
252
+ generate_btn.click(
253
+ fn=generate,
254
+ inputs=[input_image, bg_choice, fg_ratio, bg_color, seed_val, guidance, steps],
255
+ outputs=[output_rgb, output_ccm, output_glb],
256
+ concurrency_limit=1
257
+ )
258
+
259
+ # Add examples
260
+ gr.Examples(
261
+ examples=[[os.path.join("examples", i)] for i in os.listdir("examples")],
262
+ inputs=input_image
263
+ )
264
 
265
+ # Launch with minimal settings
266
+ if __name__ == "__main__":
267
+ demo.launch(
268
+ server_name="0.0.0.0",
269
+ server_port=7860,
270
+ show_error=True,
271
+ max_threads=1
272
+ )