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
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
|
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 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
|
254 |
-
# Launch with minimal
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
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 |
+
)
|