Commit ·
a1731c2
1
Parent(s): 9e975a6
Enhance app.py UI components by adding show_label and show_download_button options for better user experience. Refactor background choice and color picker for improved readability. Update demo launch settings to enable API access and error display.
Browse files
app.py
CHANGED
|
@@ -190,44 +190,80 @@ with gr.Blocks() as demo:
|
|
| 190 |
image_input = gr.Image(
|
| 191 |
label="Image input",
|
| 192 |
image_mode="RGBA",
|
| 193 |
-
sources="upload",
|
| 194 |
type="pil",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
)
|
| 196 |
-
processed_image = gr.Image(label="Processed Image", interactive=False, type="pil", image_mode="RGB")
|
| 197 |
with gr.Row():
|
| 198 |
with gr.Column():
|
| 199 |
with gr.Row():
|
| 200 |
-
background_choice = gr.Radio(
|
| 201 |
-
"Alpha as mask",
|
| 202 |
-
"Auto Remove background"
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
foreground_ratio = gr.Slider(
|
| 207 |
label="Foreground Ratio",
|
| 208 |
minimum=0.5,
|
| 209 |
maximum=1.0,
|
| 210 |
value=1.0,
|
| 211 |
step=0.05,
|
|
|
|
| 212 |
)
|
| 213 |
|
| 214 |
with gr.Column():
|
| 215 |
-
seed = gr.Number(
|
| 216 |
-
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
text_button = gr.Button("Generate 3D shape")
|
| 219 |
-
if os.path.exists("examples") and os.listdir("examples"):
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
with gr.Column():
|
| 226 |
image_output = gr.Image(interactive=False, label="Output RGB image")
|
| 227 |
xyz_output = gr.Image(interactive=False, label="Output CCM image")
|
| 228 |
output_model = gr.Model3D(
|
| 229 |
label="Output GLB",
|
| 230 |
interactive=False,
|
|
|
|
|
|
|
|
|
|
| 231 |
)
|
| 232 |
gr.Markdown("Note: Ensure that the input image is correctly pre-processed into a grey background, otherwise the results will be unpredictable.")
|
| 233 |
|
|
@@ -254,4 +290,11 @@ with gr.Blocks() as demo:
|
|
| 254 |
)
|
| 255 |
|
| 256 |
if __name__ == "__main__":
|
| 257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
image_input = gr.Image(
|
| 191 |
label="Image input",
|
| 192 |
image_mode="RGBA",
|
| 193 |
+
sources=["upload"],
|
| 194 |
type="pil",
|
| 195 |
+
show_label=True,
|
| 196 |
+
show_download_button=False
|
| 197 |
+
)
|
| 198 |
+
processed_image = gr.Image(
|
| 199 |
+
label="Processed Image",
|
| 200 |
+
interactive=False,
|
| 201 |
+
type="pil",
|
| 202 |
+
image_mode="RGB",
|
| 203 |
+
show_label=True,
|
| 204 |
+
show_download_button=False
|
| 205 |
)
|
|
|
|
| 206 |
with gr.Row():
|
| 207 |
with gr.Column():
|
| 208 |
with gr.Row():
|
| 209 |
+
background_choice = gr.Radio(
|
| 210 |
+
choices=["Alpha as mask", "Auto Remove background"],
|
| 211 |
+
value="Auto Remove background",
|
| 212 |
+
label="Background choice",
|
| 213 |
+
show_label=True
|
| 214 |
+
)
|
| 215 |
+
back_ground_color = gr.ColorPicker(
|
| 216 |
+
label="Background Color",
|
| 217 |
+
value="#7F7F7F",
|
| 218 |
+
show_label=True
|
| 219 |
+
)
|
| 220 |
foreground_ratio = gr.Slider(
|
| 221 |
label="Foreground Ratio",
|
| 222 |
minimum=0.5,
|
| 223 |
maximum=1.0,
|
| 224 |
value=1.0,
|
| 225 |
step=0.05,
|
| 226 |
+
show_label=True
|
| 227 |
)
|
| 228 |
|
| 229 |
with gr.Column():
|
| 230 |
+
seed = gr.Number(
|
| 231 |
+
value=1234,
|
| 232 |
+
label="Seed",
|
| 233 |
+
precision=0,
|
| 234 |
+
show_label=True
|
| 235 |
+
)
|
| 236 |
+
guidance_scale = gr.Number(
|
| 237 |
+
value=5.5,
|
| 238 |
+
minimum=3.0,
|
| 239 |
+
maximum=10.0,
|
| 240 |
+
label="Guidance scale",
|
| 241 |
+
show_label=True
|
| 242 |
+
)
|
| 243 |
+
step = gr.Number(
|
| 244 |
+
value=30,
|
| 245 |
+
minimum=30,
|
| 246 |
+
maximum=100,
|
| 247 |
+
label="Sample steps",
|
| 248 |
+
precision=0,
|
| 249 |
+
show_label=True
|
| 250 |
+
)
|
| 251 |
text_button = gr.Button("Generate 3D shape")
|
| 252 |
+
# if os.path.exists("examples") and os.listdir("examples"):
|
| 253 |
+
# gr.Examples(
|
| 254 |
+
# examples=[os.path.join("examples", i) for i in os.listdir("examples") if i.lower().endswith(('.png', '.jpg', '.jpeg'))],
|
| 255 |
+
# inputs=[image_input],
|
| 256 |
+
# examples_per_page=20,
|
| 257 |
+
# )
|
| 258 |
with gr.Column():
|
| 259 |
image_output = gr.Image(interactive=False, label="Output RGB image")
|
| 260 |
xyz_output = gr.Image(interactive=False, label="Output CCM image")
|
| 261 |
output_model = gr.Model3D(
|
| 262 |
label="Output GLB",
|
| 263 |
interactive=False,
|
| 264 |
+
type="filepath",
|
| 265 |
+
show_label=True,
|
| 266 |
+
show_download_button=True
|
| 267 |
)
|
| 268 |
gr.Markdown("Note: Ensure that the input image is correctly pre-processed into a grey background, otherwise the results will be unpredictable.")
|
| 269 |
|
|
|
|
| 290 |
)
|
| 291 |
|
| 292 |
if __name__ == "__main__":
|
| 293 |
+
# Ensure API endpoints are properly launched
|
| 294 |
+
demo.launch(
|
| 295 |
+
enable_queue=True,
|
| 296 |
+
api_open=True, # Enable API access
|
| 297 |
+
show_api=True, # Show API documentation
|
| 298 |
+
show_error=True,
|
| 299 |
+
allowed_paths=["examples"] # Allow access to examples directory
|
| 300 |
+
)
|