Spaces:
Running
on
Zero
Running
on
Zero
Fix step 2 error handling and wire up error_box
Browse files- __pycache__/background_edit.cpython-310.pyc +0 -0
- __pycache__/inference.cpython-310.pyc +0 -0
- __pycache__/utils.cpython-310.pyc +0 -0
- app.py +14 -5
- yolov8x-seg.pt +3 -0
__pycache__/background_edit.cpython-310.pyc
ADDED
Binary file (1.85 kB). View file
|
|
__pycache__/inference.cpython-310.pyc
ADDED
Binary file (1.35 kB). View file
|
|
__pycache__/utils.cpython-310.pyc
ADDED
Binary file (515 Bytes). View file
|
|
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
from inference import generate_with_lora
|
3 |
from background_edit import run_background_removal_and_inpaint
|
@@ -62,12 +63,14 @@ with gr.Blocks() as demo:
|
|
62 |
inputs=[input_image, prompt, negative_prompt, strength, guidance],
|
63 |
outputs=output_image,
|
64 |
)
|
65 |
-
.then(_save_to_state,
|
66 |
.then(lambda x: x, input_image, original_input)
|
67 |
)
|
68 |
|
69 |
# ─────────── STEP 2: Background Replacement ───────────
|
70 |
with gr.Tab("Step 2: Replace Background"):
|
|
|
|
|
71 |
with gr.Row():
|
72 |
inpaint_prompt = gr.Textbox(
|
73 |
label="New Background Prompt",
|
@@ -85,14 +88,20 @@ with gr.Blocks() as demo:
|
|
85 |
inpaint_btn = gr.Button("Remove Background & Inpaint", interactive=False)
|
86 |
|
87 |
def guarded_inpaint(img, prompt_bg, neg_bg):
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
inpaint_btn.click(
|
93 |
fn=guarded_inpaint,
|
94 |
inputs=[shared_output, inpaint_prompt, inpaint_negative],
|
95 |
-
outputs=inpaint_result,
|
96 |
)
|
97 |
|
98 |
# Enable the Step 2 button once Step 1 finishes
|
|
|
1 |
+
|
2 |
import gradio as gr
|
3 |
from inference import generate_with_lora
|
4 |
from background_edit import run_background_removal_and_inpaint
|
|
|
63 |
inputs=[input_image, prompt, negative_prompt, strength, guidance],
|
64 |
outputs=output_image,
|
65 |
)
|
66 |
+
.then(_save_to_state, output_image, shared_output)
|
67 |
.then(lambda x: x, input_image, original_input)
|
68 |
)
|
69 |
|
70 |
# ─────────── STEP 2: Background Replacement ───────────
|
71 |
with gr.Tab("Step 2: Replace Background"):
|
72 |
+
# … your prompts and inpaint_result …
|
73 |
+
error_box = gr.Textbox(label="Error", interactive=False, lines=2)
|
74 |
with gr.Row():
|
75 |
inpaint_prompt = gr.Textbox(
|
76 |
label="New Background Prompt",
|
|
|
88 |
inpaint_btn = gr.Button("Remove Background & Inpaint", interactive=False)
|
89 |
|
90 |
def guarded_inpaint(img, prompt_bg, neg_bg):
|
91 |
+
try:
|
92 |
+
if img is None:
|
93 |
+
raise ValueError("No image to inpaint—run Step 1 first.")
|
94 |
+
out = safe_run_background(img, prompt_bg, neg_bg)
|
95 |
+
return out, "" # success
|
96 |
+
except Exception as e:
|
97 |
+
# logs to console for debugging
|
98 |
+
print(f"[Step 2 ERROR] {type(e).__name__}: {e}", flush=True)
|
99 |
+
return None, f"{type(e).__name__}: {e}" # image=None, show error
|
100 |
|
101 |
inpaint_btn.click(
|
102 |
fn=guarded_inpaint,
|
103 |
inputs=[shared_output, inpaint_prompt, inpaint_negative],
|
104 |
+
outputs=[inpaint_result, error_box],
|
105 |
)
|
106 |
|
107 |
# Enable the Step 2 button once Step 1 finishes
|
yolov8x-seg.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c333d6a7aff884ec821050eacdab29871f3edd10d996cf48746a02f8e01f1b5d
|
3 |
+
size 144101612
|