Commit
·
e98b019
1
Parent(s):
e55aa12
Refactor Gradio interface to use a simpler structure with a single Interface instead of Blocks, enhancing clarity and usability while maintaining concurrency limits and error handling for image uploads.
Browse files
app.py
CHANGED
@@ -206,86 +206,54 @@ _DESCRIPTION = '''
|
|
206 |
* If you find the output unsatisfying, try using different seeds:)
|
207 |
'''
|
208 |
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
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 |
-
def generate(image, bg_choice, fg_ratio, bg_color, seed_val, guidance, steps):
|
260 |
-
if image is None:
|
261 |
-
raise gr.Error("No image uploaded!")
|
262 |
-
processed = preprocess_image(image, bg_choice, fg_ratio, bg_color)
|
263 |
-
return gen_image(processed, seed_val, guidance, steps)
|
264 |
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
|
285 |
-
# Launch
|
286 |
demo.launch(
|
287 |
-
server_name="0.0.0.0",
|
288 |
-
server_port=7860,
|
289 |
-
show_error=True
|
290 |
-
max_threads=1 # Control total number of workers
|
291 |
)
|
|
|
206 |
* If you find the output unsatisfying, try using different seeds:)
|
207 |
'''
|
208 |
|
209 |
+
def generate(image, bg_choice, fg_ratio, bg_color, seed_val, guidance, steps):
|
210 |
+
if image is None:
|
211 |
+
raise gr.Error("No image uploaded!")
|
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 |
)
|