Spaces:
Sleeping
Sleeping
Commit ·
cc49726
1
Parent(s): d774d01
Update interface to match desired layout and tools
Browse files
app.py
CHANGED
|
@@ -44,13 +44,15 @@ def calculate_optimal_dimensions(image: Image.Image):
|
|
| 44 |
|
| 45 |
# Inpainting function
|
| 46 |
def infer(edit_images, prompt):
|
| 47 |
-
|
|
|
|
| 48 |
if not edit_images["layers"]:
|
| 49 |
raise gr.Error("Please draw a mask.")
|
|
|
|
| 50 |
mask = edit_images["layers"][0]
|
| 51 |
width, height = calculate_optimal_dimensions(image)
|
| 52 |
seed = random.randint(0, np.iinfo(np.int32).max)
|
| 53 |
-
generator = torch.Generator(device
|
| 54 |
try:
|
| 55 |
output = pipe(
|
| 56 |
prompt=prompt,
|
|
@@ -70,18 +72,25 @@ def infer(edit_images, prompt):
|
|
| 70 |
# Gradio interface setup
|
| 71 |
with gr.Blocks() as demo:
|
| 72 |
gr.Markdown("# FLUX.1 Fill [dev]")
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
run_button.click(infer, inputs=[edit_image, prompt], outputs=result)
|
| 86 |
|
| 87 |
# Launch the demo
|
|
|
|
| 44 |
|
| 45 |
# Inpainting function
|
| 46 |
def infer(edit_images, prompt):
|
| 47 |
+
if not edit_images["background"]:
|
| 48 |
+
raise gr.Error("Please upload an image.")
|
| 49 |
if not edit_images["layers"]:
|
| 50 |
raise gr.Error("Please draw a mask.")
|
| 51 |
+
image = edit_images["background"]
|
| 52 |
mask = edit_images["layers"][0]
|
| 53 |
width, height = calculate_optimal_dimensions(image)
|
| 54 |
seed = random.randint(0, np.iinfo(np.int32).max)
|
| 55 |
+
generator = torch.Generator(device).manual_seed(seed)
|
| 56 |
try:
|
| 57 |
output = pipe(
|
| 58 |
prompt=prompt,
|
|
|
|
| 72 |
# Gradio interface setup
|
| 73 |
with gr.Blocks() as demo:
|
| 74 |
gr.Markdown("# FLUX.1 Fill [dev]")
|
| 75 |
+
with gr.Row():
|
| 76 |
+
with gr.Column(scale=1):
|
| 77 |
+
edit_image = gr.ImageEditor(
|
| 78 |
+
label="Upload and draw mask for inpainting",
|
| 79 |
+
type="pil",
|
| 80 |
+
sources=["upload"],
|
| 81 |
+
image_mode="RGB",
|
| 82 |
+
layers=False,
|
| 83 |
+
brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"),
|
| 84 |
+
height=400,
|
| 85 |
+
)
|
| 86 |
+
with gr.Column(scale=2):
|
| 87 |
+
prompt = gr.Textbox(
|
| 88 |
+
label="Prompt",
|
| 89 |
+
value="add a golden crescent moon on the forehead, glowing red cat eyes",
|
| 90 |
+
placeholder="Enter your prompt",
|
| 91 |
+
)
|
| 92 |
+
run_button = gr.Button("Run")
|
| 93 |
+
result = gr.Image(label="Result")
|
| 94 |
run_button.click(infer, inputs=[edit_image, prompt], outputs=result)
|
| 95 |
|
| 96 |
# Launch the demo
|