yizhangliu commited on
Commit
70c2a37
·
1 Parent(s): 3d01992

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -10
app.py CHANGED
@@ -176,7 +176,7 @@ model = ModelManager(
176
  )
177
 
178
  image_type = 'pil' # filepath'
179
- def predict(input, img_enhancer):
180
  if input is None:
181
  return None
182
  if image_type == 'filepath':
@@ -231,7 +231,7 @@ css = '''
231
  display: none !important;
232
  }
233
  '''
234
- set_page_elements = """async () => {
235
  function isMobile() {
236
  try {
237
  document.createEvent("TouchEvent"); return true;
@@ -260,13 +260,12 @@ set_page_elements = """async () => {
260
  const enhancer = gradioEl.querySelectorAll('#enhancer-checkbox')[0];
261
  enhancer.style.display = "none";
262
  const share_btn_container = gradioEl.querySelectorAll('#share-btn-container')[0];
263
- share_btn_container.setAttribute('style', 'width: 0px; height:0px;');
264
  } else {
265
  max_height = 800;
266
  image_upload.setAttribute('style', 'min-height: ' + max_height + 'px; overflow-x: overlay');
267
  data_image.setAttribute('style', 'height: ' + max_height + 'px');
268
  data_image_div.setAttribute('style', 'min-height: ' + max_height + 'px');
269
- image_output.setAttribute('style', 'width: ' + max_height + 'px');
270
  }
271
  group1.style.display = "none";
272
  group2.style.display = "block";
@@ -277,19 +276,32 @@ image_blocks = gr.Blocks(css=css, title='修图神器')
277
  with image_blocks as demo:
278
  with gr.Group(elem_id="group_1", visible=True) as group_1:
279
  with gr.Box():
280
- with gr.Row():
281
- with gr.Column():
282
  gallery = gr.Gallery(value=['./sample_00.jpg','./sample_00_e.jpg'], show_label=False)
283
- gallery.style(grid=[2], width=320)
284
  with gr.Row():
285
  with gr.Column():
286
  begin_button = gr.Button("Let's GO!", elem_id="begin-btn", visible=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
287
 
288
  with gr.Group(elem_id="group_2", visible=False) as group_2:
289
  with gr.Box(elem_id="work-container"):
290
  with gr.Row(elem_id="input-container"):
291
  with gr.Column():
292
- image = gr.Image(source='upload', elem_id="image_upload",tool='sketch', type=f'{image_type}',
293
  label="Upload(载入图片)", show_label=False).style(mobile_collapse=False)
294
  with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
295
  with gr.Column(elem_id="erase-container"):
@@ -308,8 +320,8 @@ with image_blocks as demo:
308
  community_icon = gr.HTML(community_icon_html, visible=False)
309
  loading_icon = gr.HTML(loading_icon_html, visible=False)
310
  share_button = gr.Button("Share to community", elem_id="share-btn", visible=False)
311
-
312
- btn_erase.click(fn=predict, inputs=[image, img_enhancer], outputs=[image_out, community_icon, loading_icon, share_button])
313
  share_button.click(None, [], [], _js=share_js)
314
 
315
  begin_button.click(fn=None, inputs=[], outputs=[group_1, group_2], _js=set_page_elements)
 
176
  )
177
 
178
  image_type = 'pil' # filepath'
179
+ def predict(input, img_enhancer):
180
  if input is None:
181
  return None
182
  if image_type == 'filepath':
 
231
  display: none !important;
232
  }
233
  '''
234
+ set_page_elements = """async() => {
235
  function isMobile() {
236
  try {
237
  document.createEvent("TouchEvent"); return true;
 
260
  const enhancer = gradioEl.querySelectorAll('#enhancer-checkbox')[0];
261
  enhancer.style.display = "none";
262
  const share_btn_container = gradioEl.querySelectorAll('#share-btn-container')[0];
263
+ share_btn_container.setAttribute('style', 'width: 0px; height:0px;');
264
  } else {
265
  max_height = 800;
266
  image_upload.setAttribute('style', 'min-height: ' + max_height + 'px; overflow-x: overlay');
267
  data_image.setAttribute('style', 'height: ' + max_height + 'px');
268
  data_image_div.setAttribute('style', 'min-height: ' + max_height + 'px');
 
269
  }
270
  group1.style.display = "none";
271
  group2.style.display = "block";
 
276
  with image_blocks as demo:
277
  with gr.Group(elem_id="group_1", visible=True) as group_1:
278
  with gr.Box():
279
+ with gr.Row(elem_id="gallery_row"):
280
+ with gr.Column(elem_id="gallery_col"):
281
  gallery = gr.Gallery(value=['./sample_00.jpg','./sample_00_e.jpg'], show_label=False)
282
+ gallery.style(grid=[2], height='500px')
283
  with gr.Row():
284
  with gr.Column():
285
  begin_button = gr.Button("Let's GO!", elem_id="begin-btn", visible=True)
286
+ with gr.Row():
287
+ with gr.Column():
288
+ gr.HTML("""
289
+ <div style='margin: 0 auto; text-align: center;color:red;'>
290
+ <p>
291
+ Solemnly promise: this application will not collect any user information and image resources.
292
+ </p>
293
+ <p>
294
+ 【郑重承诺:本应用不收集任何用户信息和图片资源。】
295
+ </p>
296
+ </div>
297
+ """
298
+ )
299
 
300
  with gr.Group(elem_id="group_2", visible=False) as group_2:
301
  with gr.Box(elem_id="work-container"):
302
  with gr.Row(elem_id="input-container"):
303
  with gr.Column():
304
+ image_input = gr.Image(source='upload', elem_id="image_upload",tool='sketch', type=f'{image_type}',
305
  label="Upload(载入图片)", show_label=False).style(mobile_collapse=False)
306
  with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
307
  with gr.Column(elem_id="erase-container"):
 
320
  community_icon = gr.HTML(community_icon_html, visible=False)
321
  loading_icon = gr.HTML(loading_icon_html, visible=False)
322
  share_button = gr.Button("Share to community", elem_id="share-btn", visible=False)
323
+
324
+ btn_erase.click(fn=predict, inputs=[image_input, img_enhancer], outputs=[image_out, community_icon, loading_icon, share_button])
325
  share_button.click(None, [], [], _js=share_js)
326
 
327
  begin_button.click(fn=None, inputs=[], outputs=[group_1, group_2], _js=set_page_elements)