Spaces:
Running
Running
yizhangliu
commited on
Commit
•
6fc03a3
1
Parent(s):
4e8fead
Update app.py
Browse files
app.py
CHANGED
@@ -192,7 +192,7 @@ def predict(input, img_enhancer):
|
|
192 |
image = np.array(image_pil)
|
193 |
mask = np.array(mask_pil.convert("L"))
|
194 |
output = model_process(image, mask, img_enhancer)
|
195 |
-
return output, gr.update(visible=True)
|
196 |
|
197 |
css = '''
|
198 |
.container {max-width: 1150px; margin: auto;padding-top: 1.5rem}
|
@@ -241,7 +241,7 @@ css = '''
|
|
241 |
display: none !important;
|
242 |
}
|
243 |
'''
|
244 |
-
|
245 |
function isMobile() {
|
246 |
try {
|
247 |
document.createEvent("TouchEvent"); return true;
|
@@ -258,9 +258,11 @@ set_page_elements = """async() => {
|
|
258 |
const group2 = gradioEl.querySelectorAll('#group_2')[0];
|
259 |
const image_upload = gradioEl.querySelectorAll('#image_upload')[0];
|
260 |
const image_output = gradioEl.querySelectorAll('#image_output')[0];
|
|
|
261 |
const data_image = gradioEl.querySelectorAll('#image_upload [data-testid="image"]')[0];
|
262 |
const data_image_div = gradioEl.querySelectorAll('#image_upload [data-testid="image"] > div')[0];
|
263 |
|
|
|
264 |
if (isMobile()) {
|
265 |
const group1_width = group1.offsetWidth;
|
266 |
|
@@ -276,6 +278,7 @@ set_page_elements = """async() => {
|
|
276 |
share_btn_container.setAttribute('style', 'width: 0px; height:0px;');
|
277 |
const share_btn_share_icon = gradioEl.querySelectorAll('#share-btn-share-icon')[0];
|
278 |
share_btn_share_icon.setAttribute('style', 'width: 0px; height:0px;');
|
|
|
279 |
} else {
|
280 |
max_height = 800;
|
281 |
image_upload.setAttribute('style', 'min-height: ' + max_height + 'px; overflow-x: overlay');
|
@@ -289,7 +292,23 @@ set_page_elements = """async() => {
|
|
289 |
}
|
290 |
group1.style.display = "none";
|
291 |
group2.style.display = "block";
|
292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
}"""
|
294 |
|
295 |
download_img = """async() => {
|
@@ -373,8 +392,12 @@ with image_blocks as demo:
|
|
373 |
enhancer_label = 'Enhanced image(processing is very slow, please check only for blurred images)'
|
374 |
img_enhancer = gr.Checkbox(label=enhancer_label).style(width=150)
|
375 |
with gr.Row(elem_id="output-container"):
|
|
|
|
|
376 |
with gr.Column():
|
377 |
-
|
|
|
|
|
378 |
with gr.Row(elem_id="download-container", visible=False) as download_container:
|
379 |
with gr.Column(elem_id="download-btn-container") as download_btn_container:
|
380 |
download_button = gr.Button(elem_id="download-btn", value="Save(⏩)")
|
@@ -384,10 +407,10 @@ with image_blocks as demo:
|
|
384 |
loading_icon = gr.HTML(loading_icon_html, elem_id="loading-icon", visible=True)
|
385 |
share_button = gr.Button("Share to community", elem_id="share-btn", visible=True)
|
386 |
|
387 |
-
erase_btn.click(fn=predict, inputs=[image_input, img_enhancer], outputs=[image_out, download_container])
|
388 |
download_button.click(None, [], [], _js=download_img)
|
389 |
share_button.click(None, [], [], _js=share_js)
|
390 |
|
391 |
-
begin_button.click(fn=None, inputs=[], outputs=[group_1, group_2], _js=
|
392 |
|
393 |
-
image_blocks.launch(server_name='0.0.0.0')
|
|
|
192 |
image = np.array(image_pil)
|
193 |
mask = np.array(mask_pil.convert("L"))
|
194 |
output = model_process(image, mask, img_enhancer)
|
195 |
+
return output, [image_pil, output], gr.update(visible=True)
|
196 |
|
197 |
css = '''
|
198 |
.container {max-width: 1150px; margin: auto;padding-top: 1.5rem}
|
|
|
241 |
display: none !important;
|
242 |
}
|
243 |
'''
|
244 |
+
start_cleaner = """async() => {
|
245 |
function isMobile() {
|
246 |
try {
|
247 |
document.createEvent("TouchEvent"); return true;
|
|
|
258 |
const group2 = gradioEl.querySelectorAll('#group_2')[0];
|
259 |
const image_upload = gradioEl.querySelectorAll('#image_upload')[0];
|
260 |
const image_output = gradioEl.querySelectorAll('#image_output')[0];
|
261 |
+
const image_output_container = gradioEl.querySelectorAll('#image-output-container')[0];
|
262 |
const data_image = gradioEl.querySelectorAll('#image_upload [data-testid="image"]')[0];
|
263 |
const data_image_div = gradioEl.querySelectorAll('#image_upload [data-testid="image"] > div')[0];
|
264 |
|
265 |
+
image_output_container.setAttribute('style', 'width: 0px; height:0px; display:none;');
|
266 |
if (isMobile()) {
|
267 |
const group1_width = group1.offsetWidth;
|
268 |
|
|
|
278 |
share_btn_container.setAttribute('style', 'width: 0px; height:0px;');
|
279 |
const share_btn_share_icon = gradioEl.querySelectorAll('#share-btn-share-icon')[0];
|
280 |
share_btn_share_icon.setAttribute('style', 'width: 0px; height:0px;');
|
281 |
+
|
282 |
} else {
|
283 |
max_height = 800;
|
284 |
image_upload.setAttribute('style', 'min-height: ' + max_height + 'px; overflow-x: overlay');
|
|
|
292 |
}
|
293 |
group1.style.display = "none";
|
294 |
group2.style.display = "block";
|
295 |
+
|
296 |
+
window['gradioEl'] = gradioEl;
|
297 |
+
window['doCheckAction'] = 0;
|
298 |
+
window['checkAction'] = function checkAction() {
|
299 |
+
try {
|
300 |
+
if (window['doCheckAction'] == 0) {
|
301 |
+
var gallery_items = window['gradioEl'].querySelectorAll('#gallery .gallery-item');
|
302 |
+
if (gallery_items && gallery_items.length == 2) {
|
303 |
+
window.clearInterval(window['checkAction_interval']);
|
304 |
+
window['doCheckAction'] = 1;
|
305 |
+
gallery_items[gallery_items.length-1].click();
|
306 |
+
}
|
307 |
+
}
|
308 |
+
} catch(e) {
|
309 |
+
}
|
310 |
+
}
|
311 |
+
window['checkAction_interval'] = window.setInterval("window.checkAction()", 500);
|
312 |
}"""
|
313 |
|
314 |
download_img = """async() => {
|
|
|
392 |
enhancer_label = 'Enhanced image(processing is very slow, please check only for blurred images)'
|
393 |
img_enhancer = gr.Checkbox(label=enhancer_label).style(width=150)
|
394 |
with gr.Row(elem_id="output-container"):
|
395 |
+
with gr.Column(elem_id="image-output-container"):
|
396 |
+
image_out = gr.Image(elem_id="image_output",label="Result", show_label=False, visible=False)
|
397 |
with gr.Column():
|
398 |
+
gallery = gr.Gallery(
|
399 |
+
label="Generated images", show_label=False, elem_id="gallery"
|
400 |
+
).style(grid=[2], height="600px")
|
401 |
with gr.Row(elem_id="download-container", visible=False) as download_container:
|
402 |
with gr.Column(elem_id="download-btn-container") as download_btn_container:
|
403 |
download_button = gr.Button(elem_id="download-btn", value="Save(⏩)")
|
|
|
407 |
loading_icon = gr.HTML(loading_icon_html, elem_id="loading-icon", visible=True)
|
408 |
share_button = gr.Button("Share to community", elem_id="share-btn", visible=True)
|
409 |
|
410 |
+
erase_btn.click(fn=predict, inputs=[image_input, img_enhancer], outputs=[image_out, gallery, download_container])
|
411 |
download_button.click(None, [], [], _js=download_img)
|
412 |
share_button.click(None, [], [], _js=share_js)
|
413 |
|
414 |
+
begin_button.click(fn=None, inputs=[], outputs=[group_1, group_2], _js=start_cleaner)
|
415 |
|
416 |
+
image_blocks.launch(server_name='0.0.0.0')
|