Update app.py
Browse files
app.py
CHANGED
|
@@ -210,7 +210,7 @@ def remove_bg(fl, s, l, v):
|
|
| 210 |
frame[m>0] = (239,239,239)
|
| 211 |
m = cv2.inRange(frame, np.array([0,0,0]), np.array([15,15,15]))
|
| 212 |
frame[m>0] = (16,16,16)
|
| 213 |
-
frame[frame_==0] = (frame / 17).astype(np.uint8)
|
| 214 |
frame[frame_==255] = (255,255,255)
|
| 215 |
|
| 216 |
cv2.imwrite(fl, frame)
|
|
@@ -259,7 +259,7 @@ def sortFiles(e):
|
|
| 259 |
e = e.split('/')
|
| 260 |
return e[len(e)-1]
|
| 261 |
|
| 262 |
-
def loadf(f, s, l, v):
|
| 263 |
if f != None and f[0] != None:
|
| 264 |
f.sort(key=sortFiles)
|
| 265 |
fnew = []
|
|
@@ -269,7 +269,9 @@ def loadf(f, s, l, v):
|
|
| 269 |
if ftype[len(ftype)-1].split('.')[1] == 'mp4':
|
| 270 |
fl = sharpest(fl, i)
|
| 271 |
|
| 272 |
-
|
|
|
|
|
|
|
| 273 |
fnew.append(fl)
|
| 274 |
|
| 275 |
return fnew, fnew
|
|
@@ -313,7 +315,8 @@ with gr.Blocks() as demo:
|
|
| 313 |
max_s = gr.Slider(minimum=0, maximum=255, step=1, value=32, label="Saturation")
|
| 314 |
max_l = gr.Slider(minimum=0, maximum=255, step=1, value=64, label="Lightness")
|
| 315 |
max_v = gr.Slider(minimum=0, maximum=255, step=1, value=16, label="Variance")
|
| 316 |
-
|
|
|
|
| 317 |
with gr.Row():
|
| 318 |
interpolation_slider = gr.Slider(minimum=1, maximum=5, step=1, value=1, label="Interpolation Steps: ")
|
| 319 |
interpolation = gr.Number(value=1, show_label=False, interactive=False)
|
|
@@ -331,10 +334,10 @@ with gr.Blocks() as demo:
|
|
| 331 |
gr.Examples(
|
| 332 |
examples=[[
|
| 333 |
["./examples/0.png", "./examples/1.png", "./examples/2.png", "./examples/3.png", "./examples/4.png"],
|
| 334 |
-
32, 64, 16
|
| 335 |
]],
|
| 336 |
fn=loadf,
|
| 337 |
-
inputs=[files_input, max_s, max_l, max_v],
|
| 338 |
outputs=[files_input, gallery_input],
|
| 339 |
cache_examples=True
|
| 340 |
)
|
|
|
|
| 210 |
frame[m>0] = (239,239,239)
|
| 211 |
m = cv2.inRange(frame, np.array([0,0,0]), np.array([15,15,15]))
|
| 212 |
frame[m>0] = (16,16,16)
|
| 213 |
+
frame[frame_==0] = (frame[frame_==0] / 17).astype(np.uint8)
|
| 214 |
frame[frame_==255] = (255,255,255)
|
| 215 |
|
| 216 |
cv2.imwrite(fl, frame)
|
|
|
|
| 259 |
e = e.split('/')
|
| 260 |
return e[len(e)-1]
|
| 261 |
|
| 262 |
+
def loadf(f, s, l, v, r_bg):
|
| 263 |
if f != None and f[0] != None:
|
| 264 |
f.sort(key=sortFiles)
|
| 265 |
fnew = []
|
|
|
|
| 269 |
if ftype[len(ftype)-1].split('.')[1] == 'mp4':
|
| 270 |
fl = sharpest(fl, i)
|
| 271 |
|
| 272 |
+
if r_bg == True:
|
| 273 |
+
fl = remove_bg(fl, s, l, v)
|
| 274 |
+
|
| 275 |
fnew.append(fl)
|
| 276 |
|
| 277 |
return fnew, fnew
|
|
|
|
| 315 |
max_s = gr.Slider(minimum=0, maximum=255, step=1, value=32, label="Saturation")
|
| 316 |
max_l = gr.Slider(minimum=0, maximum=255, step=1, value=64, label="Lightness")
|
| 317 |
max_v = gr.Slider(minimum=0, maximum=255, step=1, value=16, label="Variance")
|
| 318 |
+
rbg = gr.Checkbox(label="Remove background", value=True)
|
| 319 |
+
files_input.upload(fn=loadf, inputs=[files_input, max_s, max_l, max_v, rbg], outputs=[files_input, gallery_input])
|
| 320 |
with gr.Row():
|
| 321 |
interpolation_slider = gr.Slider(minimum=1, maximum=5, step=1, value=1, label="Interpolation Steps: ")
|
| 322 |
interpolation = gr.Number(value=1, show_label=False, interactive=False)
|
|
|
|
| 334 |
gr.Examples(
|
| 335 |
examples=[[
|
| 336 |
["./examples/0.png", "./examples/1.png", "./examples/2.png", "./examples/3.png", "./examples/4.png"],
|
| 337 |
+
32, 64, 16, True
|
| 338 |
]],
|
| 339 |
fn=loadf,
|
| 340 |
+
inputs=[files_input, max_s, max_l, max_v, rbg],
|
| 341 |
outputs=[files_input, gallery_input],
|
| 342 |
cache_examples=True
|
| 343 |
)
|