SkalskiP commited on
Commit
e128936
1 Parent(s): 1539189

advanced settings

Browse files
Files changed (1) hide show
  1. app.py +54 -4
app.py CHANGED
@@ -1,5 +1,7 @@
1
  from typing import Tuple
2
 
 
 
3
  import gradio as gr
4
  import spaces
5
  import torch
@@ -14,6 +16,8 @@ creating this amazing model, and a big thanks to [Gothos](https://github.com/Got
14
  for taking it to the next level by enabling inpainting with the FLUX.
15
  """
16
 
 
 
17
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
18
 
19
  pipe = FluxInpaintPipeline.from_pretrained(
@@ -44,7 +48,15 @@ def resize_image_dimensions(
44
 
45
 
46
  @spaces.GPU()
47
- def process(input_image_editor, input_text, progress=gr.Progress(track_tqdm=True)):
 
 
 
 
 
 
 
 
48
  if not input_text:
49
  gr.Info("Please enter a text prompt.")
50
  return None
@@ -64,14 +76,18 @@ def process(input_image_editor, input_text, progress=gr.Progress(track_tqdm=True
64
  resized_image = image.resize((width, height), Image.LANCZOS)
65
  resized_mask = mask.resize((width, height), Image.NEAREST)
66
 
 
 
 
67
  return pipe(
68
  prompt=input_text,
69
  image=resized_image,
70
  mask_image=resized_mask,
71
  width=width,
72
  height=height,
73
- strength=0.7,
74
- num_inference_steps=24
 
75
  ).images[0], resized_mask
76
 
77
 
@@ -86,6 +102,7 @@ with gr.Blocks() as demo:
86
  image_mode='RGB',
87
  layers=False,
88
  brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"))
 
89
  with gr.Row():
90
  input_text_component = gr.Text(
91
  label="Prompt",
@@ -96,6 +113,35 @@ with gr.Blocks() as demo:
96
  )
97
  submit_button_component = gr.Button(
98
  value='Submit', variant='primary', scale=0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  with gr.Column():
100
  output_gallery_component = gr.Gallery(
101
  columns=[1],
@@ -110,7 +156,11 @@ with gr.Blocks() as demo:
110
  fn=process,
111
  inputs=[
112
  input_image_editor_component,
113
- input_text_component
 
 
 
 
114
  ],
115
  outputs=[
116
  output_gallery_component
 
1
  from typing import Tuple
2
 
3
+ import random
4
+ import numpy as np
5
  import gradio as gr
6
  import spaces
7
  import torch
 
16
  for taking it to the next level by enabling inpainting with the FLUX.
17
  """
18
 
19
+ MAX_SEED = np.iinfo(np.int32).max
20
+ MAX_IMAGE_SIZE = 2048
21
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
22
 
23
  pipe = FluxInpaintPipeline.from_pretrained(
 
48
 
49
 
50
  @spaces.GPU()
51
+ def process(
52
+ input_image_editor: dict,
53
+ input_text: str,
54
+ seed_slicer: int,
55
+ randomize_seed_checkbox: bool,
56
+ strength_slider: float,
57
+ num_inference_steps_slider: int,
58
+ progress=gr.Progress(track_tqdm=True)
59
+ ):
60
  if not input_text:
61
  gr.Info("Please enter a text prompt.")
62
  return None
 
76
  resized_image = image.resize((width, height), Image.LANCZOS)
77
  resized_mask = mask.resize((width, height), Image.NEAREST)
78
 
79
+ if randomize_seed_checkbox:
80
+ seed_slicer = random.randint(0, MAX_SEED)
81
+ generator = torch.Generator().manual_seed(seed_slicer)
82
  return pipe(
83
  prompt=input_text,
84
  image=resized_image,
85
  mask_image=resized_mask,
86
  width=width,
87
  height=height,
88
+ strength=strength_slider,
89
+ generator=generator,
90
+ num_inference_steps=num_inference_steps_slider
91
  ).images[0], resized_mask
92
 
93
 
 
102
  image_mode='RGB',
103
  layers=False,
104
  brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"))
105
+
106
  with gr.Row():
107
  input_text_component = gr.Text(
108
  label="Prompt",
 
113
  )
114
  submit_button_component = gr.Button(
115
  value='Submit', variant='primary', scale=0)
116
+
117
+ with gr.Accordion("Advanced Settings", open=False):
118
+ seed_slicer_component = gr.Slider(
119
+ label="Seed",
120
+ minimum=0,
121
+ maximum=MAX_SEED,
122
+ step=1,
123
+ value=0,
124
+ )
125
+
126
+ randomize_seed_checkbox_component = gr.Checkbox(
127
+ label="Randomize seed", value=True)
128
+
129
+ with gr.Row():
130
+ strength_slider_component = gr.Slider(
131
+ label="Strength",
132
+ minimum=0,
133
+ maximum=1,
134
+ step=0.01,
135
+ value=0.75,
136
+ )
137
+
138
+ num_inference_steps_slider_component = gr.Slider(
139
+ label="Number of inference steps",
140
+ minimum=1,
141
+ maximum=50,
142
+ step=1,
143
+ value=20,
144
+ )
145
  with gr.Column():
146
  output_gallery_component = gr.Gallery(
147
  columns=[1],
 
156
  fn=process,
157
  inputs=[
158
  input_image_editor_component,
159
+ input_text_component,
160
+ seed_slicer_component,
161
+ randomize_seed_checkbox_component,
162
+ strength_slider_component,
163
+ num_inference_steps_slider_component
164
  ],
165
  outputs=[
166
  output_gallery_component