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
app.py
CHANGED
@@ -207,85 +207,79 @@ _DESCRIPTION = '''
|
|
207 |
'''
|
208 |
|
209 |
# Create Gradio interface
|
210 |
-
with gr.Blocks(
|
|
|
211 |
gr.Markdown(_DESCRIPTION)
|
212 |
-
|
213 |
with gr.Row():
|
214 |
with gr.Column():
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
label="Steps"
|
250 |
)
|
251 |
-
generate_btn = gr.Button("Generate 3D Model")
|
252 |
-
|
253 |
with gr.Column():
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
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 |
-
#
|
289 |
-
demo.queue().launch(
|
290 |
-
show_error=True
|
|
|
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 |
)
|