Spaces:
Running
Running
yizhangliu
commited on
Commit
•
9f9dde1
1
Parent(s):
d638400
Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,8 @@ import time
|
|
13 |
import imghdr
|
14 |
from loguru import logger
|
15 |
|
|
|
|
|
16 |
from lama_cleaner.model_manager import ModelManager
|
17 |
from lama_cleaner.schema import Config
|
18 |
|
@@ -190,7 +192,7 @@ def predict(input, img_enhancer):
|
|
190 |
image = np.array(image_pil)
|
191 |
mask = np.array(mask_pil.convert("L"))
|
192 |
output = model_process(image, mask, img_enhancer)
|
193 |
-
return output
|
194 |
|
195 |
|
196 |
css = '''
|
@@ -212,6 +214,22 @@ css = '''
|
|
212 |
transform: rotate(360deg);
|
213 |
}
|
214 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
'''
|
216 |
set_page_elements = """async () => {
|
217 |
function isMobile() {
|
@@ -222,30 +240,31 @@ set_page_elements = """async () => {
|
|
222 |
}
|
223 |
}
|
224 |
|
225 |
-
|
226 |
if (!gradioEl) {
|
227 |
gradioEl = document.querySelector('body > gradio-app');
|
228 |
}
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
|
236 |
if (isMobile()) {
|
237 |
-
|
238 |
image_upload.setAttribute('style', 'width:' + (group1_width - 13*2) + 'px; min-height:none;');
|
239 |
data_image.setAttribute('style', 'width: ' + (group1_width - 14*2) + 'px;min-height:none;');
|
240 |
data_image_div.setAttribute('style', 'width: ' + (group1_width - 14*2) + 'px;min-height:none;');
|
241 |
image_output.setAttribute('style', 'width: ' + (group1_width - 13*2) + 'px;min-height:none;');
|
242 |
-
|
243 |
enhancer.style.display = "none";
|
244 |
} else {
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
|
|
249 |
}
|
250 |
group1.style.display = "none";
|
251 |
group2.style.display = "block";
|
@@ -283,9 +302,14 @@ with image_blocks as demo:
|
|
283 |
with gr.Row(elem_id="output-container"):
|
284 |
with gr.Column():
|
285 |
image_out = gr.Image(elem_id="image_output",label="Result", show_label=False)
|
|
|
|
|
|
|
|
|
286 |
|
287 |
-
btn_erase.click(fn=predict, inputs=[image, img_enhancer], outputs=[image_out])
|
|
|
288 |
|
289 |
begin_button.click(fn=None, inputs=[], outputs=[group_1, group_2], _js=set_page_elements)
|
290 |
-
|
291 |
image_blocks.launch()
|
|
|
13 |
import imghdr
|
14 |
from loguru import logger
|
15 |
|
16 |
+
from share_btn import community_icon_html, loading_icon_html, share_js
|
17 |
+
|
18 |
from lama_cleaner.model_manager import ModelManager
|
19 |
from lama_cleaner.schema import Config
|
20 |
|
|
|
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), gr.update(visible=True), gr.update(visible=True)
|
196 |
|
197 |
|
198 |
css = '''
|
|
|
214 |
transform: rotate(360deg);
|
215 |
}
|
216 |
}
|
217 |
+
#share-btn-container {
|
218 |
+
display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
|
219 |
+
}
|
220 |
+
#share-btn {
|
221 |
+
all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;
|
222 |
+
}
|
223 |
+
#share-btn * {
|
224 |
+
all: unset;
|
225 |
+
}
|
226 |
+
#share-btn-container div:nth-child(-n+2){
|
227 |
+
width: auto !important;
|
228 |
+
min-height: 0px !important;
|
229 |
+
}
|
230 |
+
#share-btn-container .wrap {
|
231 |
+
display: none !important;
|
232 |
+
}
|
233 |
'''
|
234 |
set_page_elements = """async () => {
|
235 |
function isMobile() {
|
|
|
240 |
}
|
241 |
}
|
242 |
|
243 |
+
const gradioEl = document.querySelector('body > gradio-app').shadowRoot;
|
244 |
if (!gradioEl) {
|
245 |
gradioEl = document.querySelector('body > gradio-app');
|
246 |
}
|
247 |
+
const group1 = gradioEl.querySelectorAll('#group_1')[0];
|
248 |
+
const group2 = gradioEl.querySelectorAll('#group_2')[0];
|
249 |
+
const image_upload = gradioEl.querySelectorAll('#image_upload')[0];
|
250 |
+
const image_output = gradioEl.querySelectorAll('#image_output')[0];
|
251 |
+
const data_image = gradioEl.querySelectorAll('#image_upload [data-testid="image"]')[0];
|
252 |
+
const data_image_div = gradioEl.querySelectorAll('#image_upload [data-testid="image"] > div')[0];
|
253 |
|
254 |
if (isMobile()) {
|
255 |
+
const group1_width = group1.offsetWidth;
|
256 |
image_upload.setAttribute('style', 'width:' + (group1_width - 13*2) + 'px; min-height:none;');
|
257 |
data_image.setAttribute('style', 'width: ' + (group1_width - 14*2) + 'px;min-height:none;');
|
258 |
data_image_div.setAttribute('style', 'width: ' + (group1_width - 14*2) + 'px;min-height:none;');
|
259 |
image_output.setAttribute('style', 'width: ' + (group1_width - 13*2) + 'px;min-height:none;');
|
260 |
+
const enhancer = gradioEl.querySelectorAll('#enhancer-checkbox')[0];
|
261 |
enhancer.style.display = "none";
|
262 |
} else {
|
263 |
+
max_height = 800;
|
264 |
+
image_upload.setAttribute('style', 'min-height: ' + max_height + 'px; overflow-x: overlay');
|
265 |
+
data_image.setAttribute('style', 'height: ' + max_height + 'px');
|
266 |
+
data_image_div.setAttribute('style', 'min-height: ' + max_height + 'px');
|
267 |
+
image_output.setAttribute('style', 'width: ' + max_height + 'px');
|
268 |
}
|
269 |
group1.style.display = "none";
|
270 |
group2.style.display = "block";
|
|
|
302 |
with gr.Row(elem_id="output-container"):
|
303 |
with gr.Column():
|
304 |
image_out = gr.Image(elem_id="image_output",label="Result", show_label=False)
|
305 |
+
with gr.Group(elem_id="share-btn-container"):
|
306 |
+
community_icon = gr.HTML(community_icon_html, visible=False)
|
307 |
+
loading_icon = gr.HTML(loading_icon_html, visible=False)
|
308 |
+
share_button = gr.Button("Share to community", elem_id="share-btn", visible=False)
|
309 |
|
310 |
+
btn_erase.click(fn=predict, inputs=[image, img_enhancer], outputs=[image_out, community_icon, loading_icon, share_button])
|
311 |
+
share_button.click(None, [], [], _js=share_js)
|
312 |
|
313 |
begin_button.click(fn=None, inputs=[], outputs=[group_1, group_2], _js=set_page_elements)
|
314 |
+
|
315 |
image_blocks.launch()
|