ncoop57
commited on
Commit
·
2924167
1
Parent(s):
c637e67
Add a loading gif and a quality selector for downloading the video
Browse files- app.py +12 -3
- loading.gif +0 -0
app.py
CHANGED
|
@@ -30,6 +30,8 @@ def get_embedding(txt_model, vis_model, query, video):
|
|
| 30 |
|
| 31 |
def find_frames(url, txt_model, vis_model, desc, seconds, top_k):
|
| 32 |
text = st.text("Downloading video (Descargando video)...")
|
|
|
|
|
|
|
| 33 |
probe = ffmpeg.probe(url)
|
| 34 |
video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
|
| 35 |
width = int(video_stream['width'])
|
|
@@ -51,8 +53,9 @@ def find_frames(url, txt_model, vis_model, desc, seconds, top_k):
|
|
| 51 |
txt_embd, img_embds = get_embedding(txt_model, vis_model, desc, video)
|
| 52 |
cos_scores = np.array(util.cos_sim(txt_embd, img_embds))
|
| 53 |
ids = np.argsort(cos_scores)[0][-top_k:]
|
| 54 |
-
|
| 55 |
imgs = [Image.fromarray(video[i]) for i in ids]
|
|
|
|
|
|
|
| 56 |
text.empty()
|
| 57 |
st.image(imgs)
|
| 58 |
|
|
@@ -87,6 +90,7 @@ def clifs_page(txt_model, vis_model):
|
|
| 87 |
"Top K",
|
| 88 |
min_value=1,
|
| 89 |
max_value=5,
|
|
|
|
| 90 |
step=1,
|
| 91 |
)
|
| 92 |
desc = st.sidebar.text_input(
|
|
@@ -99,19 +103,24 @@ def clifs_page(txt_model, vis_model):
|
|
| 99 |
value='https://youtu.be/xUv6XgPwGaQ',
|
| 100 |
help="Youtube video you want to search (Video de Youtube que desea búscar)",
|
| 101 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
submit_button = st.sidebar.button("Search (Búscar)")
|
| 104 |
if submit_button:
|
| 105 |
-
ydl_opts = {"format": "mp4[height=
|
| 106 |
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
| 107 |
info_dict = ydl.extract_info(url, download=False)
|
| 108 |
video_url = info_dict.get("url", None)
|
| 109 |
find_frames(video_url, txt_model, vis_model, desc, seconds, top_k)
|
| 110 |
|
| 111 |
PAGES = {
|
|
|
|
| 112 |
"Home": main_page,
|
| 113 |
"Inicio": inicio_pagina,
|
| 114 |
-
"CLIFS": clifs_page
|
| 115 |
}
|
| 116 |
|
| 117 |
|
|
|
|
| 30 |
|
| 31 |
def find_frames(url, txt_model, vis_model, desc, seconds, top_k):
|
| 32 |
text = st.text("Downloading video (Descargando video)...")
|
| 33 |
+
# gif from https://giphy.com/gifs/alan-DfSXiR60W9MVq
|
| 34 |
+
gif_runner = st.image("./loading.gif")
|
| 35 |
probe = ffmpeg.probe(url)
|
| 36 |
video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
|
| 37 |
width = int(video_stream['width'])
|
|
|
|
| 53 |
txt_embd, img_embds = get_embedding(txt_model, vis_model, desc, video)
|
| 54 |
cos_scores = np.array(util.cos_sim(txt_embd, img_embds))
|
| 55 |
ids = np.argsort(cos_scores)[0][-top_k:]
|
|
|
|
| 56 |
imgs = [Image.fromarray(video[i]) for i in ids]
|
| 57 |
+
|
| 58 |
+
gif_runner.empty()
|
| 59 |
text.empty()
|
| 60 |
st.image(imgs)
|
| 61 |
|
|
|
|
| 90 |
"Top K",
|
| 91 |
min_value=1,
|
| 92 |
max_value=5,
|
| 93 |
+
value=3,
|
| 94 |
step=1,
|
| 95 |
)
|
| 96 |
desc = st.sidebar.text_input(
|
|
|
|
| 103 |
value='https://youtu.be/xUv6XgPwGaQ',
|
| 104 |
help="Youtube video you want to search (Video de Youtube que desea búscar)",
|
| 105 |
)
|
| 106 |
+
quality = st.sidebar.radio(
|
| 107 |
+
"Quality of the Video (Calidad del Video)",
|
| 108 |
+
[144, 240, 360, 480],
|
| 109 |
+
help="Quality of the video to download. Higher quality takes more time (Calidad del video para descargar. Calidad más alta toma más tiempo)",
|
| 110 |
+
)
|
| 111 |
|
| 112 |
submit_button = st.sidebar.button("Search (Búscar)")
|
| 113 |
if submit_button:
|
| 114 |
+
ydl_opts = {"format": f"mp4[height={quality}]"}
|
| 115 |
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
| 116 |
info_dict = ydl.extract_info(url, download=False)
|
| 117 |
video_url = info_dict.get("url", None)
|
| 118 |
find_frames(video_url, txt_model, vis_model, desc, seconds, top_k)
|
| 119 |
|
| 120 |
PAGES = {
|
| 121 |
+
"CLIFS": clifs_page,
|
| 122 |
"Home": main_page,
|
| 123 |
"Inicio": inicio_pagina,
|
|
|
|
| 124 |
}
|
| 125 |
|
| 126 |
|
loading.gif
ADDED
|