Spaces:
mashroo
/
Running on Zero

YoussefAnso commited on
Commit
4871683
·
1 Parent(s): 0e00a44

Revamp Gradio interface for 3D character generation, enhancing input options and output display while streamlining the image processing workflow.

Browse files
Files changed (1) hide show
  1. app.py +67 -73
app.py CHANGED
@@ -207,85 +207,79 @@ _DESCRIPTION = '''
207
  '''
208
 
209
  # Create Gradio interface
210
- with gr.Blocks(title="CRM: 3D Character Generation from Single Image") as demo:
 
211
  gr.Markdown(_DESCRIPTION)
212
-
213
  with gr.Row():
214
  with gr.Column():
215
- input_image = gr.Image(label="Input Image", type="pil")
216
- background_choice = gr.Radio(
217
- choices=["Remove Background", "Custom Background"],
218
- value="Remove Background",
219
- label="Background Option"
220
- )
221
- foreground_ratio = gr.Slider(
222
- minimum=0.1,
223
- maximum=1.0,
224
- value=1.0,
225
- step=0.1,
226
- label="Foreground Ratio"
227
- )
228
- back_groud_color = gr.ColorPicker(
229
- label="Background Color",
230
- value="#FFFFFF"
231
- )
232
- seed = gr.Number(
233
- label="Seed",
234
- value=42,
235
- precision=0
236
- )
237
- scale = gr.Slider(
238
- minimum=1.0,
239
- maximum=20.0,
240
- value=7.5,
241
- step=0.1,
242
- label="Guidance Scale"
243
- )
244
- step = gr.Slider(
245
- minimum=1,
246
- maximum=100,
247
- value=50,
248
- step=1,
249
- label="Steps"
250
  )
251
- generate_btn = gr.Button("Generate 3D Model")
252
-
253
  with gr.Column():
254
- processed_image = gr.Image(label="Processed Image", type="pil")
255
- output_image = gr.Image(label="Generated Image", type="pil")
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
289
- demo.queue().launch(
290
- show_error=True # Only keep error display for debugging
 
291
  )
 
207
  '''
208
 
209
  # Create Gradio interface
210
+ with gr.Blocks() as demo:
211
+ gr.Markdown("# CRM: Single Image to 3D Textured Mesh with Convolutional Reconstruction Model")
212
  gr.Markdown(_DESCRIPTION)
 
213
  with gr.Row():
214
  with gr.Column():
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(label="Processed Image", interactive=False, type="pil", image_mode="RGB")
223
+ with gr.Row():
224
+ with gr.Column():
225
+ with gr.Row():
226
+ background_choice = gr.Radio([
227
+ "Alpha as mask",
228
+ "Auto Remove background"
229
+ ], value="Auto Remove background",
230
+ label="background choice")
231
+ back_groud_color = gr.ColorPicker(label="Background Color", value="#7F7F7F", interactive=False)
232
+ foreground_ratio = gr.Slider(
233
+ label="Foreground Ratio",
234
+ minimum=0.5,
235
+ maximum=1.0,
236
+ value=1.0,
237
+ step=0.05,
238
+ )
239
+
240
+ with gr.Column():
241
+ seed = gr.Number(value=1234, label="seed", precision=0)
242
+ guidance_scale = gr.Number(value=5.5, minimum=3, maximum=10, label="guidance_scale")
243
+ step = gr.Number(value=30, minimum=30, maximum=100, label="sample steps", precision=0)
244
+ text_button = gr.Button("Generate 3D shape")
245
+ gr.Examples(
246
+ examples=[os.path.join("examples", i) for i in os.listdir("examples")],
247
+ inputs=[image_input],
248
+ examples_per_page=20,
 
249
  )
 
 
250
  with gr.Column():
251
+ image_output = gr.Image(interactive=False, label="Output RGB image")
252
+ xyz_output = gr.Image(interactive=False, label="Output CCM image")
253
+ output_model = gr.Model3D(
254
+ label="Output GLB",
255
+ interactive=False,
256
+ )
257
+ gr.Markdown("Note: Ensure that the input image is correctly pre-processed into a grey background, otherwise the results will be unpredictable.")
258
+
259
+ inputs = [
260
+ processed_image,
261
+ seed,
262
+ guidance_scale,
263
+ step,
264
+ ]
265
+ outputs = [
266
+ image_output,
267
+ xyz_output,
268
+ output_model,
269
+ ]
270
 
271
+ text_button.click(fn=check_input_image, inputs=[image_input]).success(
272
+ fn=preprocess_image,
273
+ inputs=[image_input, background_choice, foreground_ratio, back_groud_color],
274
+ outputs=[processed_image],
275
+ ).success(
276
+ fn=gen_image,
277
+ inputs=inputs,
278
+ outputs=outputs,
 
 
 
 
 
 
 
 
 
 
279
  )
280
 
281
+ # Launch the interface
282
+ demo.queue(concurrency_count=1).launch(
283
+ show_error=True,
284
+ share=False
285
  )