tastelikefeet commited on
Commit
c693371
1 Parent(s): dd4d502
Files changed (1) hide show
  1. app.py +28 -27
app.py CHANGED
@@ -123,49 +123,49 @@ with block:
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>在“输入图像”中上传or选择Example里面的一张图片(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>输入对应的参数,例如prompt等,点击Run进行生成(Input prompt or reference image for generating new contents)
139
- - ⭐️ <b>step4 (optional):</b>此外支持换背景操作,上传目标风格背景,执行完step3后点击Run进行生成(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="输入图",scale=2)
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(['前景点选', '背景点选'], label='分割点选: ', value='前景点选',scale=2)
153
- undo_button = gr.Button('撤销点选至上一步', elem_id="btnSEG",scale=1)
154
- prompt = gr.Textbox(label="Prompt (支持中英文)", placeholder="请输入期望的文本描述",value='',lines=1)
155
- run_button = gr.Button("生成图像(Run",elem_id="btn")
156
 
157
- with gr.Accordion("更多输入参数 (推荐使用)", open=False, elem_id="accordion1"):
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="人脸 Prompt (支持中英文)", value='good face, beautiful face, best quality')
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("推荐��作品广场",elem_id="recBut")
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(