Spaces:
mashroo
/
Running on Zero

YoussefAnso commited on
Commit
2d4bf78
·
1 Parent(s): f084c0e
Files changed (3) hide show
  1. README.md +2 -1
  2. app.py +50 -62
  3. requirements.txt +1 -1
README.md CHANGED
@@ -4,10 +4,11 @@ emoji: 📊
4
  colorFrom: gray
5
  colorTo: red
6
  sdk: gradio
7
- sdk_version: 4.21.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
4
  colorFrom: gray
5
  colorTo: red
6
  sdk: gradio
7
+ sdk_version: 4.44.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
+ hardware: gpu-a100
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -183,79 +183,67 @@ _DESCRIPTION = '''
183
  with gr.Blocks() as demo:
184
  gr.Markdown("# CRM: Single Image to 3D Textured Mesh with Convolutional Reconstruction Model")
185
  gr.Markdown(_DESCRIPTION)
 
186
  with gr.Row():
187
  with gr.Column():
 
 
 
 
 
 
 
188
  with gr.Row():
189
- image_input = gr.Image(
190
- label="Image input",
191
- image_mode="RGBA",
192
- sources="upload",
193
- type="pil",
194
  )
195
- processed_image = gr.Image(label="Processed Image", interactive=False, type="pil", image_mode="RGB")
196
  with gr.Row():
197
- with gr.Column():
198
- with gr.Row():
199
- background_choice = gr.Radio([
200
- "Alpha as mask",
201
- "Auto Remove background"
202
- ], value="Auto Remove background",
203
- label="backgroud choice")
204
- # do_remove_background = gr.Checkbox(label=, value=True)
205
- # force_remove = gr.Checkbox(label=, value=False)
206
- back_groud_color = gr.ColorPicker(label="Background Color", value="#7F7F7F", interactive=False)
207
- foreground_ratio = gr.Slider(
208
- label="Foreground Ratio",
209
- minimum=0.5,
210
- maximum=1.0,
211
- value=1.0,
212
- step=0.05,
213
- )
214
-
215
- with gr.Column():
216
- seed = gr.Number(value=1234, label="seed", precision=0)
217
- guidance_scale = gr.Number(value=5.5, minimum=3, maximum=10, label="guidance_scale")
218
- step = gr.Number(value=30, minimum=30, maximum=100, label="sample steps", precision=0)
219
- text_button = gr.Button("Generate 3D shape")
220
  gr.Examples(
221
  examples=[os.path.join("examples", i) for i in os.listdir("examples")],
222
  inputs=[image_input],
223
- examples_per_page = 20,
224
  )
 
225
  with gr.Column():
226
- image_output = gr.Image(interactive=False, label="Output RGB image")
227
- xyz_ouput = gr.Image(interactive=False, label="Output CCM image")
228
-
229
- output_model = gr.Model3D(
230
- label="Output OBJ",
231
- interactive=False,
232
- )
233
  gr.Markdown("Note: Ensure that the input image is correctly pre-processed into a grey background, otherwise the results will be unpredictable.")
234
 
235
- inputs = [
236
- image_input,
237
- background_choice,
238
- foreground_ratio,
239
- back_groud_color,
240
- seed,
241
- guidance_scale,
242
- step,
243
- ]
244
- outputs = [
245
- image_output,
246
- xyz_ouput,
247
- output_model,
248
- ]
249
-
250
- text_button.click(
251
- fn=process_and_generate,
252
- inputs=inputs,
253
- outputs=outputs,
 
 
 
254
  )
255
-
256
  demo.queue().launch(
257
- server_name="0.0.0.0",
258
- server_port=7860,
259
- share=True, # Enable public sharing
260
- show_error=True # Show detailed error messages
261
- )
 
183
  with gr.Blocks() as demo:
184
  gr.Markdown("# CRM: Single Image to 3D Textured Mesh with Convolutional Reconstruction Model")
185
  gr.Markdown(_DESCRIPTION)
186
+
187
  with gr.Row():
188
  with gr.Column():
189
+ image_input = gr.Image(
190
+ label="Image input",
191
+ type="pil",
192
+ image_mode="RGBA",
193
+ sources=["upload"]
194
+ )
195
+
196
  with gr.Row():
197
+ background_choice = gr.Radio(
198
+ choices=["Alpha as mask", "Auto Remove background"],
199
+ value="Auto Remove background",
200
+ label="Background choice"
 
201
  )
202
+
203
  with gr.Row():
204
+ seed = gr.Number(value=1234, label="Seed", precision=0)
205
+ guidance_scale = gr.Number(value=5.5, minimum=3, maximum=10, label="Guidance scale")
206
+ step = gr.Number(value=30, minimum=30, maximum=100, label="Sample steps", precision=0)
207
+
208
+ generate_btn = gr.Button("Generate 3D shape")
209
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  gr.Examples(
211
  examples=[os.path.join("examples", i) for i in os.listdir("examples")],
212
  inputs=[image_input],
213
+ examples_per_page=20
214
  )
215
+
216
  with gr.Column():
217
+ image_output = gr.Image(label="Output RGB image", type="pil")
218
+ xyz_output = gr.Image(label="Output CCM image", type="pil")
219
+ output_model = gr.Model3D(label="Output 3D Model")
220
+
 
 
 
221
  gr.Markdown("Note: Ensure that the input image is correctly pre-processed into a grey background, otherwise the results will be unpredictable.")
222
 
223
+ def process_and_generate_simple(image, seed, scale, step):
224
+ if image is None:
225
+ raise gr.Error("No image uploaded!")
226
+
227
+ # Use default values for background processing
228
+ processed = preprocess_image(image, "Auto Remove background", 1.0, "#7F7F7F")
229
+
230
+ # Generate the 3D model
231
+ pipeline.set_seed(seed)
232
+ rt_dict = pipeline(processed, scale=scale, step=step)
233
+ stage1_images = rt_dict["stage1_images"]
234
+ stage2_images = rt_dict["stage2_images"]
235
+ np_imgs = np.concatenate(stage1_images, 1)
236
+ np_xyzs = np.concatenate(stage2_images, 1)
237
+
238
+ glb_path = generate3d(model, np_imgs, np_xyzs, args.device)
239
+ return Image.fromarray(np_imgs), Image.fromarray(np_xyzs), glb_path
240
+
241
+ generate_btn.click(
242
+ fn=process_and_generate_simple,
243
+ inputs=[image_input, seed, guidance_scale, step],
244
+ outputs=[image_output, xyz_output, output_model]
245
  )
246
+
247
  demo.queue().launch(
248
+
249
+ )
 
 
 
requirements.txt CHANGED
@@ -8,7 +8,7 @@ opencv-contrib-python-headless==4.9.0.80
8
  opencv-python-headless==4.9.0.80
9
  xformers
10
  omegaconf
11
- gradio==4.44.1
12
  rembg
13
  git+https://github.com/NVlabs/nvdiffrast
14
  pygltflib
 
8
  opencv-python-headless==4.9.0.80
9
  xformers
10
  omegaconf
11
+ gradio==3.16.0
12
  rembg
13
  git+https://github.com/NVlabs/nvdiffrast
14
  pygltflib