File size: 1,150 Bytes
9fda83d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import numpy as np
import gradio as gr

from commons.selfie_seg import (
    load_from_webcam,
    load_from_static_image,
    load_from_video
)

# Optional[str | PIL.Image | np.narray]

title = "Image and Video background changer"
desc = "This simple app leverages google selfie segmentation via mediapipe to change background from bot images and videos. The \
        backgroud type can be solid pictures, random images, or blur"

imgs = os.listdir("bg_imgs/")
rnd_img = "bg_imgs/" + np.random.choice(imgs)


img_app = gr.Interface(
    load_from_static_image, 
    [gr.Image(), gr.Dropdown(["random_image", "solid_colors", "blur"], label="Background Type", placeholder="Background type")], #,gr.Textbox(label="Background can be blur, a set of random_image, or a solid_colors")], # 
    gr.Image()
    )

vid_app = gr.Interface(
    load_from_video,
    [gr.Video(source="upload"), gr.Dropdown(["ragindom_image", "solid_colors", "blur"], placeholder="Background type", show_label="Video")],
    [gr.Video(interactive=False, label="Video")]
    )

gr.TabbedInterface([img_app, vid_app], ["Image", "Video"]).launch(
    max_threads = 4)