vid-url-dl-mod / app.py
Omnibus's picture
Update app.py
5e47d3b
raw
history blame
1.65 kB
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():
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
with gr.Blocks() as app:
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.Row(visible=False):
text_input=gr.Textbox()
text_output=gr.Textbox()
url_params=gr.JSON()
go_btn.click(dl,inp_url,outp_file)
app.load(fn=predict, inputs=[text_input,url_params], outputs=[text_output,text_input],_js=load_js)
app.launch()