Randomdude432 commited on
Commit
cc49726
·
1 Parent(s): d774d01

Update interface to match desired layout and tools

Browse files
Files changed (1) hide show
  1. app.py +23 -14
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
- image = edit_images["background"]
 
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=device).manual_seed(seed)
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
- edit_image = gr.ImageEditor(
74
- label="Upload and draw mask for inpainting",
75
- type="pil",
76
- sources=["upload", "webcam"],
77
- image_mode="RGB",
78
- layers=False,
79
- brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"),
80
- height=600,
81
- )
82
- prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt")
83
- run_button = gr.Button("Run")
84
- result = gr.Image(label="Result")
 
 
 
 
 
 
 
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