Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
210cb7f
1
Parent(s):
d25fccd
fixes to jpg
Browse files
app.py
CHANGED
@@ -492,10 +492,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
492 |
with gr.Row():
|
493 |
with gr.Column(scale=1):
|
494 |
gr.Markdown("### Input Image (Required)")
|
495 |
-
input_image_component = gr.Image(
|
496 |
-
type="
|
497 |
-
image_mode="RGBA",
|
498 |
-
format="png",
|
499 |
label="Upload Image",
|
500 |
sources=["upload"],
|
501 |
interactive=True,
|
@@ -578,12 +577,10 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
578 |
|
579 |
# --- Backend Function for Running the Script ---
|
580 |
def execute_autoforge_script(
|
581 |
-
current_filaments_df_state_val,
|
582 |
):
|
583 |
# 0. Validate Inputs
|
584 |
-
if
|
585 |
-
not input_image_path
|
586 |
-
): # Covers None and empty string from gr.Image(type="filepath")
|
587 |
gr.Error("Input Image is required! Please upload an image.")
|
588 |
capture_exception(Exception("Input Image is required!"))
|
589 |
return create_empty_error_outputs("Error: Input Image is required!")
|
@@ -632,28 +629,12 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
632 |
command.extend(["--output_folder", run_output_dir_val])
|
633 |
command.extend(["--disable_visualization_for_gradio","1"])
|
634 |
|
635 |
-
base_filename = os.path.basename(input_image_path)
|
636 |
-
script_input_image_path = os.path.join(run_output_dir_val, base_filename)
|
637 |
try:
|
638 |
-
img = Image.open(input_image_path)
|
639 |
# decide where to store the image we pass to Autoforge
|
640 |
-
base_no_ext, _ = os.path.splitext(os.path.basename(input_image_path))
|
641 |
script_input_image_path = os.path.join(
|
642 |
-
run_output_dir_val,
|
643 |
)
|
644 |
-
|
645 |
-
if img.mode in ("RGBA", "LA") or (
|
646 |
-
img.mode == "P" and "transparency" in img.info
|
647 |
-
):
|
648 |
-
# the uploaded file has an alpha channel – save it as PNG
|
649 |
-
img.save(script_input_image_path, format="PNG")
|
650 |
-
else:
|
651 |
-
# no alpha present – just copy the file in whatever format it was
|
652 |
-
script_input_image_path = os.path.join(
|
653 |
-
run_output_dir_val, os.path.basename(input_image_path)
|
654 |
-
)
|
655 |
-
shutil.copy(input_image_path, script_input_image_path)
|
656 |
-
|
657 |
command.extend(["--input_image", script_input_image_path])
|
658 |
except Exception as e:
|
659 |
capture_exception(e)
|
|
|
492 |
with gr.Row():
|
493 |
with gr.Column(scale=1):
|
494 |
gr.Markdown("### Input Image (Required)")
|
495 |
+
input_image_component = gr.Image( # keep transparency alive
|
496 |
+
type="pil", # <- no temporary JPEG cache
|
497 |
+
image_mode="RGBA", # tells Gradio to expect alpha
|
|
|
498 |
label="Upload Image",
|
499 |
sources=["upload"],
|
500 |
interactive=True,
|
|
|
577 |
|
578 |
# --- Backend Function for Running the Script ---
|
579 |
def execute_autoforge_script(
|
580 |
+
current_filaments_df_state_val, input_image, *accordion_param_values
|
581 |
):
|
582 |
# 0. Validate Inputs
|
583 |
+
if input_image is None:
|
|
|
|
|
584 |
gr.Error("Input Image is required! Please upload an image.")
|
585 |
capture_exception(Exception("Input Image is required!"))
|
586 |
return create_empty_error_outputs("Error: Input Image is required!")
|
|
|
629 |
command.extend(["--output_folder", run_output_dir_val])
|
630 |
command.extend(["--disable_visualization_for_gradio","1"])
|
631 |
|
|
|
|
|
632 |
try:
|
|
|
633 |
# decide where to store the image we pass to Autoforge
|
|
|
634 |
script_input_image_path = os.path.join(
|
635 |
+
run_output_dir_val, "input_image.png"
|
636 |
)
|
637 |
+
input_image.save(script_input_image_path, format="PNG")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
638 |
command.extend(["--input_image", script_input_image_path])
|
639 |
except Exception as e:
|
640 |
capture_exception(e)
|