(Hopefully) Final Touches
Browse files- Fix an issue with label erroneously provided to gr.State initialization
- Minor adjustments and optimizations
app.py
CHANGED
|
@@ -1,11 +1,6 @@
|
|
| 1 |
##!/usr/bin/env python3
|
| 2 |
# -*- coding: utf-8 -*-
|
| 3 |
import os
|
| 4 |
-
|
| 5 |
-
# print("Installing correct gradio version...")
|
| 6 |
-
# os.system("pip install 'gradio>=3.50.0,<3.51.0' 'accelerate>=0.26.0' 'fsspec[http]==2024.6.1' --force-reinstall -q")
|
| 7 |
-
# print("Installing Finished!")
|
| 8 |
-
|
| 9 |
import gradio as gr
|
| 10 |
import cv2
|
| 11 |
from PIL import Image
|
|
@@ -173,9 +168,9 @@ with block:
|
|
| 173 |
with gr.Tabs(elem_classes=["feedback"]):
|
| 174 |
with gr.TabItem("Input Image"):
|
| 175 |
input_image = gr.Image(type="numpy", label="input",scale=2, height=640)
|
| 176 |
-
original_image = gr.State(value=None
|
| 177 |
original_mask = gr.State(value=None)
|
| 178 |
-
selected_points = gr.State([]
|
| 179 |
with gr.Row(elem_id="Seg"):
|
| 180 |
radio = gr.Radio(['foreground', 'background'], label='Click to seg: ', value='foreground',scale=2)
|
| 181 |
undo_button = gr.Button('Undo seg', elem_id="btnSEG",scale=1)
|
|
@@ -184,7 +179,7 @@ with block:
|
|
| 184 |
label="Negative Prompt",
|
| 185 |
max_lines=5,
|
| 186 |
placeholder="Please input your negative prompt",
|
| 187 |
-
value='ugly, low quality',lines=1
|
| 188 |
)
|
| 189 |
with gr.Group():
|
| 190 |
with gr.Row():
|
|
@@ -198,7 +193,7 @@ with block:
|
|
| 198 |
)
|
| 199 |
with gr.Group():
|
| 200 |
seed = gr.Slider(
|
| 201 |
-
label="Seed: ", minimum=0, maximum=2147483647, step=1, value=
|
| 202 |
)
|
| 203 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=False)
|
| 204 |
|
|
@@ -209,12 +204,12 @@ with block:
|
|
| 209 |
minimum=1,
|
| 210 |
maximum=12,
|
| 211 |
step=0.1,
|
| 212 |
-
value=
|
| 213 |
)
|
| 214 |
num_inference_steps = gr.Slider(
|
| 215 |
label="Number of inference steps",
|
| 216 |
minimum=1,
|
| 217 |
-
maximum=
|
| 218 |
step=1,
|
| 219 |
value=50,
|
| 220 |
)
|
|
@@ -310,7 +305,7 @@ with block:
|
|
| 310 |
# draw points
|
| 311 |
output_mask = None
|
| 312 |
if len(sel_pix) != 0:
|
| 313 |
-
if isinstance(orig_img, int): # if orig_img is int, the image
|
| 314 |
temp = cv2.imread(image_examples[orig_img][0])
|
| 315 |
temp = cv2.cvtColor(temp, cv2.COLOR_BGR2RGB)
|
| 316 |
else:
|
|
|
|
| 1 |
##!/usr/bin/env python3
|
| 2 |
# -*- coding: utf-8 -*-
|
| 3 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
import cv2
|
| 6 |
from PIL import Image
|
|
|
|
| 168 |
with gr.Tabs(elem_classes=["feedback"]):
|
| 169 |
with gr.TabItem("Input Image"):
|
| 170 |
input_image = gr.Image(type="numpy", label="input",scale=2, height=640)
|
| 171 |
+
original_image = gr.State(value=None)
|
| 172 |
original_mask = gr.State(value=None)
|
| 173 |
+
selected_points = gr.State([])
|
| 174 |
with gr.Row(elem_id="Seg"):
|
| 175 |
radio = gr.Radio(['foreground', 'background'], label='Click to seg: ', value='foreground',scale=2)
|
| 176 |
undo_button = gr.Button('Undo seg', elem_id="btnSEG",scale=1)
|
|
|
|
| 179 |
label="Negative Prompt",
|
| 180 |
max_lines=5,
|
| 181 |
placeholder="Please input your negative prompt",
|
| 182 |
+
value='ugly, low quality, amateur, doodle, sketch',lines=1
|
| 183 |
)
|
| 184 |
with gr.Group():
|
| 185 |
with gr.Row():
|
|
|
|
| 193 |
)
|
| 194 |
with gr.Group():
|
| 195 |
seed = gr.Slider(
|
| 196 |
+
label="Seed: ", minimum=0, maximum=2147483647, step=1, value=694201337
|
| 197 |
)
|
| 198 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=False)
|
| 199 |
|
|
|
|
| 204 |
minimum=1,
|
| 205 |
maximum=12,
|
| 206 |
step=0.1,
|
| 207 |
+
value=3.5,
|
| 208 |
)
|
| 209 |
num_inference_steps = gr.Slider(
|
| 210 |
label="Number of inference steps",
|
| 211 |
minimum=1,
|
| 212 |
+
maximum=100,
|
| 213 |
step=1,
|
| 214 |
value=50,
|
| 215 |
)
|
|
|
|
| 305 |
# draw points
|
| 306 |
output_mask = None
|
| 307 |
if len(sel_pix) != 0:
|
| 308 |
+
if isinstance(orig_img, int): # if orig_img is int, select the image from examples
|
| 309 |
temp = cv2.imread(image_examples[orig_img][0])
|
| 310 |
temp = cv2.cvtColor(temp, cv2.COLOR_BGR2RGB)
|
| 311 |
else:
|