Spaces:
Build error
Build error
Commit ·
db55863
1
Parent(s): 7d3e5db
Change AI model settings test
Browse files
app.py
CHANGED
|
@@ -43,18 +43,17 @@ def create_full_mask(image):
|
|
| 43 |
|
| 44 |
@spaces.GPU(duration=120)
|
| 45 |
def infer(
|
| 46 |
-
|
| 47 |
prompt,
|
| 48 |
seed=42,
|
| 49 |
randomize_seed=False,
|
| 50 |
width=1024,
|
| 51 |
height=1024,
|
| 52 |
-
guidance_scale=
|
| 53 |
-
num_inference_steps=
|
| 54 |
):
|
| 55 |
-
if not
|
| 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:
|
|
@@ -104,13 +103,11 @@ with gr.Blocks(css=css) as demo:
|
|
| 104 |
)
|
| 105 |
with gr.Row():
|
| 106 |
with gr.Column():
|
| 107 |
-
|
| 108 |
-
label="Upload image for editing
|
| 109 |
type="pil",
|
| 110 |
-
sources=["upload"
|
| 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 |
)
|
| 116 |
prompt = gr.Text(
|
|
@@ -120,6 +117,11 @@ with gr.Blocks(css=css) as demo:
|
|
| 120 |
placeholder="Enter your prompt",
|
| 121 |
container=False,
|
| 122 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
run_button = gr.Button("Run")
|
| 124 |
result = gr.Image(label="Result", show_label=False)
|
| 125 |
with gr.Accordion("Advanced Settings", open=False):
|
|
@@ -152,22 +154,22 @@ with gr.Blocks(css=css) as demo:
|
|
| 152 |
guidance_scale = gr.Slider(
|
| 153 |
label="Guidance Scale",
|
| 154 |
minimum=1,
|
| 155 |
-
maximum=
|
| 156 |
step=0.5,
|
| 157 |
-
value=
|
| 158 |
)
|
| 159 |
num_inference_steps = gr.Slider(
|
| 160 |
label="Number of inference steps",
|
| 161 |
minimum=1,
|
| 162 |
maximum=50,
|
| 163 |
step=1,
|
| 164 |
-
value=
|
| 165 |
)
|
| 166 |
gr.on(
|
| 167 |
triggers=[run_button.click, prompt.submit],
|
| 168 |
fn=infer,
|
| 169 |
inputs=[
|
| 170 |
-
|
| 171 |
prompt,
|
| 172 |
seed,
|
| 173 |
randomize_seed,
|
|
|
|
| 43 |
|
| 44 |
@spaces.GPU(duration=120)
|
| 45 |
def infer(
|
| 46 |
+
image,
|
| 47 |
prompt,
|
| 48 |
seed=42,
|
| 49 |
randomize_seed=False,
|
| 50 |
width=1024,
|
| 51 |
height=1024,
|
| 52 |
+
guidance_scale=50,
|
| 53 |
+
num_inference_steps=28,
|
| 54 |
):
|
| 55 |
+
if not image:
|
| 56 |
raise gr.Error("Please upload an image.")
|
|
|
|
| 57 |
mask = create_full_mask(image) # Auto-generate full white mask
|
| 58 |
width, height = calculate_optimal_dimensions(image)
|
| 59 |
if randomize_seed:
|
|
|
|
| 103 |
)
|
| 104 |
with gr.Row():
|
| 105 |
with gr.Column():
|
| 106 |
+
image_input = gr.Image(
|
| 107 |
+
label="Upload image for editing",
|
| 108 |
type="pil",
|
| 109 |
+
sources=["upload"], # Only upload button
|
| 110 |
image_mode="RGB",
|
|
|
|
|
|
|
| 111 |
height=600,
|
| 112 |
)
|
| 113 |
prompt = gr.Text(
|
|
|
|
| 117 |
placeholder="Enter your prompt",
|
| 118 |
container=False,
|
| 119 |
)
|
| 120 |
+
gr.Examples(
|
| 121 |
+
examples=examples,
|
| 122 |
+
inputs=[prompt],
|
| 123 |
+
label="Example Prompts",
|
| 124 |
+
)
|
| 125 |
run_button = gr.Button("Run")
|
| 126 |
result = gr.Image(label="Result", show_label=False)
|
| 127 |
with gr.Accordion("Advanced Settings", open=False):
|
|
|
|
| 154 |
guidance_scale = gr.Slider(
|
| 155 |
label="Guidance Scale",
|
| 156 |
minimum=1,
|
| 157 |
+
maximum=50, # Updated max to 50
|
| 158 |
step=0.5,
|
| 159 |
+
value=50, # Updated default to 50
|
| 160 |
)
|
| 161 |
num_inference_steps = gr.Slider(
|
| 162 |
label="Number of inference steps",
|
| 163 |
minimum=1,
|
| 164 |
maximum=50,
|
| 165 |
step=1,
|
| 166 |
+
value=28, # Updated default to 28
|
| 167 |
)
|
| 168 |
gr.on(
|
| 169 |
triggers=[run_button.click, prompt.submit],
|
| 170 |
fn=infer,
|
| 171 |
inputs=[
|
| 172 |
+
image_input,
|
| 173 |
prompt,
|
| 174 |
seed,
|
| 175 |
randomize_seed,
|