File size: 2,105 Bytes
7f88dd7
b4d7fed
 
56afb5e
5e47d3b
9e24192
 
 
 
 
 
 
 
5e47d3b
e90bb7a
 
 
 
9e24192
 
 
 
 
 
 
 
e793092
7f88dd7
 
46fd8e8
34d9197
 
 
c173614
34d9197
b187599
8690dda
fde2ec3
e25c521
 
b187599
 
34d9197
6ef6ed7
34d9197
e90bb7a
7f88dd7
9e24192
e90bb7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9e24192
 
 
8c0fcd2
e90bb7a
 
9e24192
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import gradio as gr 
import yt_dlp
import os 
import json
import backgroundremover
load_js = """
function(text_input, url_params) {
    console.log(text_input, url_params);
    const params = new URLSearchParams(window.location.search);
    url_params = Object.fromEntries(params);
    return [text_input, url_params]
}
"""

def rem_bg(inp):
    #transparent .mov
    os.system(f'backgroundremover -i "{inp}" -tv -o "{inp}.mov"')
    return f'{inp}.mov'
def predict(text, url_params):
    mod_url=""
    mod=gr.HTML("")
    out = None
    valid=gr.update(visible=False)
    mod_url = url_params.get('url')
    print (mod_url)
    return ["" + text + "", mod_url]

def dl(inp):
    out = None
    out_file=[]
    try:
        inp_out=inp.replace("https://","")
        inp_out=inp_out.replace("/","_").replace(".","_")
        os.system(f'yt-dlp "{inp}" --trim-filenames 100 -o "{inp_out}.mp4"')  
        out = f"{inp_out}.mp4"
        try:
            with open(f"{inp_out}.info.json", "r") as f:
                f_out = f.read()
            json_object = json.loads(f_out)
            out_json = json.dumps(json_object, indent=4)
        except Exception as e:
            print (e)
    except Exception as e:
        print (e)
        out = None
    return out,out,out

with gr.Blocks() as app:
    with gr.Tab("Load"):
        inp_url = gr.Textbox()
        go_btn = gr.Button("Run")
        with gr.Row():
            with gr.Column():
                outp_vid=gr.Video()
            with gr.Column():
                outp_file=gr.Textbox()
    with gr.Tab("Rem BG"):
        with gr.Row():    
            with gr.Column():
                rem_btn=gr.Button()
                in_vid=gr.Video()
            with gr.Column():
                rem_vid=gr.Video()
    with gr.Row(visible=False):
        text_input=gr.Textbox()
        text_output=gr.Textbox()
        url_params=gr.JSON()
    rem_btn.click(rem_bg,in_vid,rem_vid)
    go_btn.click(dl,inp_url,[outp_vid,in_vid,outp_file])
    app.load(fn=predict, inputs=[text_input,url_params], outputs=[text_output,text_input],_js=load_js)
app.launch()