Commit
·
39dcad5
1
Parent(s):
1f1e8f3
Refactor Gradio interface to encapsulate image processing logic within a dedicated function, enhancing error handling for image uploads and streamlining event chaining for improved clarity.
Browse files
app.py
CHANGED
@@ -256,24 +256,32 @@ with gr.Blocks() as demo:
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
260 |
text_button.click(
|
261 |
-
fn=
|
262 |
-
inputs=[
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
outputs=[
|
|
|
|
|
|
|
|
|
272 |
)
|
273 |
|
274 |
-
# Launch the interface
|
275 |
demo.launch(
|
276 |
show_error=True,
|
277 |
-
max_threads=1
|
278 |
-
share=True
|
279 |
)
|
|
|
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 |
text_button.click(
|
266 |
+
fn=generate,
|
267 |
+
inputs=[
|
268 |
+
image_input,
|
269 |
+
background_choice,
|
270 |
+
foreground_ratio,
|
271 |
+
back_groud_color,
|
272 |
+
seed,
|
273 |
+
guidance_scale,
|
274 |
+
step
|
275 |
+
],
|
276 |
+
outputs=[
|
277 |
+
image_output,
|
278 |
+
xyz_output,
|
279 |
+
output_model
|
280 |
+
]
|
281 |
)
|
282 |
|
283 |
+
# Launch the interface without share parameter since we're on Hugging Face Spaces
|
284 |
demo.launch(
|
285 |
show_error=True,
|
286 |
+
max_threads=1
|
|
|
287 |
)
|