Spaces:
Build error
Build error
Commit ·
7d3e5db
1
Parent(s): cea8146
Fix mask issues, set default values for sliders.
Browse files
app.py
CHANGED
|
@@ -34,6 +34,13 @@ def calculate_optimal_dimensions(image: Image.Image):
|
|
| 34 |
return width, height
|
| 35 |
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
@spaces.GPU(duration=120)
|
| 38 |
def infer(
|
| 39 |
edit_images,
|
|
@@ -42,20 +49,18 @@ def infer(
|
|
| 42 |
randomize_seed=False,
|
| 43 |
width=1024,
|
| 44 |
height=1024,
|
| 45 |
-
guidance_scale=
|
| 46 |
-
num_inference_steps=
|
| 47 |
):
|
| 48 |
if not edit_images["background"]:
|
| 49 |
raise gr.Error("Please upload an image.")
|
| 50 |
-
if not edit_images["layers"]:
|
| 51 |
-
raise gr.Error("Please draw a mask.")
|
| 52 |
image = edit_images["background"]
|
| 53 |
-
mask =
|
| 54 |
width, height = calculate_optimal_dimensions(image)
|
| 55 |
if randomize_seed:
|
| 56 |
seed = random.randint(0, MAX_SEED)
|
| 57 |
pipe = FluxFillPipeline.from_pretrained(
|
| 58 |
-
"black-forest-labs/FLUX.1-
|
| 59 |
).to("cuda")
|
| 60 |
generator = torch.Generator("cuda").manual_seed(seed)
|
| 61 |
try:
|
|
@@ -76,6 +81,7 @@ def infer(
|
|
| 76 |
|
| 77 |
|
| 78 |
examples = [
|
|
|
|
| 79 |
"a tiny astronaut hatching from an egg on the moon",
|
| 80 |
"a cat holding a sign that says hello world",
|
| 81 |
"an anime illustration of a wiener schnitzel",
|
|
@@ -99,11 +105,11 @@ with gr.Blocks(css=css) as demo:
|
|
| 99 |
with gr.Row():
|
| 100 |
with gr.Column():
|
| 101 |
edit_image = gr.ImageEditor(
|
| 102 |
-
label="Upload
|
| 103 |
type="pil",
|
| 104 |
sources=["upload", "webcam"],
|
| 105 |
image_mode="RGB",
|
| 106 |
-
layers=False,
|
| 107 |
brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"),
|
| 108 |
height=600,
|
| 109 |
)
|
|
@@ -148,14 +154,14 @@ with gr.Blocks(css=css) as demo:
|
|
| 148 |
minimum=1,
|
| 149 |
maximum=30,
|
| 150 |
step=0.5,
|
| 151 |
-
value=
|
| 152 |
)
|
| 153 |
num_inference_steps = gr.Slider(
|
| 154 |
label="Number of inference steps",
|
| 155 |
minimum=1,
|
| 156 |
maximum=50,
|
| 157 |
step=1,
|
| 158 |
-
value=
|
| 159 |
)
|
| 160 |
gr.on(
|
| 161 |
triggers=[run_button.click, prompt.submit],
|
|
|
|
| 34 |
return width, height
|
| 35 |
|
| 36 |
|
| 37 |
+
def create_full_mask(image):
|
| 38 |
+
"""Generate a fully white mask for the entire image."""
|
| 39 |
+
return Image.fromarray(
|
| 40 |
+
np.ones((image.height, image.width), dtype=np.uint8) * 255
|
| 41 |
+
).convert("L")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
@spaces.GPU(duration=120)
|
| 45 |
def infer(
|
| 46 |
edit_images,
|
|
|
|
| 49 |
randomize_seed=False,
|
| 50 |
width=1024,
|
| 51 |
height=1024,
|
| 52 |
+
guidance_scale=30,
|
| 53 |
+
num_inference_steps=50,
|
| 54 |
):
|
| 55 |
if not edit_images["background"]:
|
| 56 |
raise gr.Error("Please upload an image.")
|
|
|
|
|
|
|
| 57 |
image = edit_images["background"]
|
| 58 |
+
mask = create_full_mask(image) # Auto-generate full white mask
|
| 59 |
width, height = calculate_optimal_dimensions(image)
|
| 60 |
if randomize_seed:
|
| 61 |
seed = random.randint(0, MAX_SEED)
|
| 62 |
pipe = FluxFillPipeline.from_pretrained(
|
| 63 |
+
"black-forest-labs/FLUX.1-FILL-dev", torch_dtype=torch.bfloat16
|
| 64 |
).to("cuda")
|
| 65 |
generator = torch.Generator("cuda").manual_seed(seed)
|
| 66 |
try:
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
examples = [
|
| 84 |
+
"Add a glowing crescent moon on the forehead, vivid red eyes, and a shadowy, dark, misty background to the subject, while preserving the exact structure and details of the original human face, animal, or object",
|
| 85 |
"a tiny astronaut hatching from an egg on the moon",
|
| 86 |
"a cat holding a sign that says hello world",
|
| 87 |
"an anime illustration of a wiener schnitzel",
|
|
|
|
| 105 |
with gr.Row():
|
| 106 |
with gr.Column():
|
| 107 |
edit_image = gr.ImageEditor(
|
| 108 |
+
label="Upload image for editing (no mask required)",
|
| 109 |
type="pil",
|
| 110 |
sources=["upload", "webcam"],
|
| 111 |
image_mode="RGB",
|
| 112 |
+
layers=False, # No layers needed as mask is auto-generated
|
| 113 |
brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"),
|
| 114 |
height=600,
|
| 115 |
)
|
|
|
|
| 154 |
minimum=1,
|
| 155 |
maximum=30,
|
| 156 |
step=0.5,
|
| 157 |
+
value=30, # Updated default to 30
|
| 158 |
)
|
| 159 |
num_inference_steps = gr.Slider(
|
| 160 |
label="Number of inference steps",
|
| 161 |
minimum=1,
|
| 162 |
maximum=50,
|
| 163 |
step=1,
|
| 164 |
+
value=50, # Updated default to 50
|
| 165 |
)
|
| 166 |
gr.on(
|
| 167 |
triggers=[run_button.click, prompt.submit],
|