Spaces:
Running
on
A10G
Running
on
A10G
tastelikefeet
commited on
Commit
•
c693371
1
Parent(s):
dd4d502
up6
Browse files
app.py
CHANGED
@@ -123,49 +123,49 @@ with block:
|
|
123 |
""")
|
124 |
|
125 |
with gr.Tabs(elem_classes=["Tab"]):
|
126 |
-
with gr.TabItem("
|
127 |
gr.Gallery(value=showcases,
|
128 |
height=800,
|
129 |
columns=4,
|
130 |
object_fit="scale-down"
|
131 |
)
|
132 |
-
with gr.TabItem("
|
133 |
-
with gr.Accordion(label="🧭
|
134 |
with gr.Row(equal_height=True):
|
135 |
gr.Markdown("""
|
136 |
-
- ⭐️ <b>step1:</b
|
137 |
-
- ⭐️ <b>step2:</b
|
138 |
-
- ⭐️ <b>step3:</b
|
139 |
-
- ⭐️ <b>step4
|
140 |
""")
|
141 |
with gr.Row():
|
142 |
with gr.Column():
|
143 |
with gr.Column(elem_id="Input"):
|
144 |
with gr.Row():
|
145 |
with gr.Tabs(elem_classes=["feedback"]):
|
146 |
-
with gr.TabItem("
|
147 |
-
input_image = gr.Image(type="numpy", label="
|
148 |
-
original_image = gr.State(value=None,label="
|
149 |
original_mask = gr.State(value=None)
|
150 |
-
selected_points = gr.State([],label="
|
151 |
with gr.Row(elem_id="Seg"):
|
152 |
-
radio = gr.Radio(['
|
153 |
-
undo_button = gr.Button('
|
154 |
-
prompt = gr.Textbox(label="Prompt
|
155 |
-
run_button = gr.Button("
|
156 |
|
157 |
-
with gr.Accordion("
|
158 |
with gr.Row(elem_id="Image"):
|
159 |
with gr.Tabs(elem_classes=["feedback1"]):
|
160 |
-
with gr.TabItem("
|
161 |
-
source_background = gr.Image(type="numpy", label="
|
162 |
|
163 |
-
face_prompt = gr.Textbox(label="
|
164 |
with gr.Column():
|
165 |
with gr.Tabs(elem_classes=["feedback"]):
|
166 |
-
with gr.TabItem("
|
167 |
result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", preview=True)
|
168 |
-
recommend=gr.Button("
|
169 |
request_id=gr.State(value="")
|
170 |
gallery_flag=gr.State(value=False)
|
171 |
with gr.Row():
|
@@ -173,7 +173,7 @@ with block:
|
|
173 |
def process_example(input_image, prompt, source_background, original_image, selected_points):
|
174 |
return input_image, prompt, source_background, original_image, []
|
175 |
example = gr.Examples(
|
176 |
-
label="
|
177 |
examples=image_examples,
|
178 |
inputs=[input_image, prompt, source_background, original_image, selected_points],
|
179 |
outputs=[input_image, prompt, source_background, original_image, selected_points],
|
@@ -224,9 +224,9 @@ with block:
|
|
224 |
return masked_img, output_mask
|
225 |
|
226 |
def get_point(img, sel_pix, point_type, evt: gr.SelectData):
|
227 |
-
if point_type == '
|
228 |
sel_pix.append((evt.index, 1)) # append the foreground_point
|
229 |
-
elif point_type == '
|
230 |
sel_pix.append((evt.index, 0)) # append the background_point
|
231 |
else:
|
232 |
sel_pix.append((evt.index, 1)) # default foreground_point
|
@@ -262,7 +262,7 @@ with block:
|
|
262 |
temp, output_mask = segmentation(temp, sel_pix)
|
263 |
return temp.astype(np.uint8), output_mask
|
264 |
else:
|
265 |
-
gr.Error("
|
266 |
|
267 |
undo_button.click(
|
268 |
undo_points,
|
@@ -272,6 +272,7 @@ with block:
|
|
272 |
|
273 |
def upload_to_img_gallery(img, res, re_id, flag):
|
274 |
if flag:
|
|
|
275 |
if isinstance(img, int):
|
276 |
image_name = image_examples[img][0]
|
277 |
img = cv2.imread(image_name)
|
@@ -282,9 +283,9 @@ with block:
|
|
282 |
r = cv2.cvtColor(r, cv2.COLOR_BGR2RGB)
|
283 |
_ = upload_np_2_oss(r, name=re_id+f"_res_{idx}.jpg", gallery=True)
|
284 |
flag=False
|
285 |
-
gr.Info("
|
286 |
else:
|
287 |
-
gr.Info("
|
288 |
return flag
|
289 |
|
290 |
recommend.click(
|
|
|
123 |
""")
|
124 |
|
125 |
with gr.Tabs(elem_classes=["Tab"]):
|
126 |
+
with gr.TabItem("Image Gallery"):
|
127 |
gr.Gallery(value=showcases,
|
128 |
height=800,
|
129 |
columns=4,
|
130 |
object_fit="scale-down"
|
131 |
)
|
132 |
+
with gr.TabItem("Image Create"):
|
133 |
+
with gr.Accordion(label="🧭 Instructions:", open=True, elem_id="accordion"):
|
134 |
with gr.Row(equal_height=True):
|
135 |
gr.Markdown("""
|
136 |
+
- ⭐️ <b>step1:</b>Upload or select one image from Example
|
137 |
+
- ⭐️ <b>step2:</b>Click on Input-image to select the object to be retained
|
138 |
+
- ⭐️ <b>step3:</b>Input prompt or reference image (highly-recommended) for generating new contents
|
139 |
+
- ⭐️ <b>step4:</b>Click Run button
|
140 |
""")
|
141 |
with gr.Row():
|
142 |
with gr.Column():
|
143 |
with gr.Column(elem_id="Input"):
|
144 |
with gr.Row():
|
145 |
with gr.Tabs(elem_classes=["feedback"]):
|
146 |
+
with gr.TabItem("Input Image"):
|
147 |
+
input_image = gr.Image(type="numpy", label="input",scale=2)
|
148 |
+
original_image = gr.State(value=None,label="index")
|
149 |
original_mask = gr.State(value=None)
|
150 |
+
selected_points = gr.State([],label="click points")
|
151 |
with gr.Row(elem_id="Seg"):
|
152 |
+
radio = gr.Radio(['foreground', 'background'], label='Click to seg: ', value='foreground',scale=2)
|
153 |
+
undo_button = gr.Button('Undo seg', elem_id="btnSEG",scale=1)
|
154 |
+
prompt = gr.Textbox(label="Prompt", placeholder="Please input your prompt",value='',lines=1)
|
155 |
+
run_button = gr.Button("Run",elem_id="btn")
|
156 |
|
157 |
+
with gr.Accordion("More input params (highly-recommended)", open=False, elem_id="accordion1"):
|
158 |
with gr.Row(elem_id="Image"):
|
159 |
with gr.Tabs(elem_classes=["feedback1"]):
|
160 |
+
with gr.TabItem("Reference Image (Optional)"):
|
161 |
+
source_background = gr.Image(type="numpy", label="Background Image")
|
162 |
|
163 |
+
face_prompt = gr.Textbox(label="Face Prompt", value='good face, beautiful face, best quality')
|
164 |
with gr.Column():
|
165 |
with gr.Tabs(elem_classes=["feedback"]):
|
166 |
+
with gr.TabItem("Outputs"):
|
167 |
result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", preview=True)
|
168 |
+
recommend=gr.Button("Recommend results to Image Gallery",elem_id="recBut")
|
169 |
request_id=gr.State(value="")
|
170 |
gallery_flag=gr.State(value=False)
|
171 |
with gr.Row():
|
|
|
173 |
def process_example(input_image, prompt, source_background, original_image, selected_points):
|
174 |
return input_image, prompt, source_background, original_image, []
|
175 |
example = gr.Examples(
|
176 |
+
label="Input Example",
|
177 |
examples=image_examples,
|
178 |
inputs=[input_image, prompt, source_background, original_image, selected_points],
|
179 |
outputs=[input_image, prompt, source_background, original_image, selected_points],
|
|
|
224 |
return masked_img, output_mask
|
225 |
|
226 |
def get_point(img, sel_pix, point_type, evt: gr.SelectData):
|
227 |
+
if point_type == 'foreground':
|
228 |
sel_pix.append((evt.index, 1)) # append the foreground_point
|
229 |
+
elif point_type == 'background':
|
230 |
sel_pix.append((evt.index, 0)) # append the background_point
|
231 |
else:
|
232 |
sel_pix.append((evt.index, 1)) # default foreground_point
|
|
|
262 |
temp, output_mask = segmentation(temp, sel_pix)
|
263 |
return temp.astype(np.uint8), output_mask
|
264 |
else:
|
265 |
+
gr.Error("Nothing to Undo")
|
266 |
|
267 |
undo_button.click(
|
268 |
undo_points,
|
|
|
272 |
|
273 |
def upload_to_img_gallery(img, res, re_id, flag):
|
274 |
if flag:
|
275 |
+
gr.Info("Image uploading")
|
276 |
if isinstance(img, int):
|
277 |
image_name = image_examples[img][0]
|
278 |
img = cv2.imread(image_name)
|
|
|
283 |
r = cv2.cvtColor(r, cv2.COLOR_BGR2RGB)
|
284 |
_ = upload_np_2_oss(r, name=re_id+f"_res_{idx}.jpg", gallery=True)
|
285 |
flag=False
|
286 |
+
gr.Info("Images have beend uploaded and are under check")
|
287 |
else:
|
288 |
+
gr.Info("Nothing to to")
|
289 |
return flag
|
290 |
|
291 |
recommend.click(
|