Spaces:
Build error
Build error
File size: 4,237 Bytes
f849799 7971a7a b9cd4c4 7971a7a 3b3290d 8d6b883 7971a7a 8d6b883 2935ca0 8d6b883 2935ca0 a4158a1 2935ca0 8d6b883 7971a7a 39557de 2935ca0 8d6b883 f849799 b9cd4c4 2935ca0 f849799 2935ca0 f849799 2935ca0 f849799 a7b0fd6 2935ca0 f849799 8d6b883 b9cd4c4 2935ca0 8d6b883 2935ca0 f849799 7f2c8f8 a7b0fd6 7f2c8f8 a4158a1 f849799 |
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 73 74 75 76 77 78 79 80 81 82 83 84 85 |
import logging
import gradio as gr
from config import *
from videomatch import index_hashes_for_video, get_decent_distance, \
get_video_indices, compare_videos, get_change_points, get_videomatch_df
from plot import plot_comparison, plot_multi_comparison
logging.basicConfig()
logging.getLogger().setLevel(logging.INFO)
def get_comparison(url, target, MIN_DISTANCE = 4):
""" Function for Gradio to combine all helper functions"""
video_index, hash_vectors, target_indices = get_video_indices(url, target, MIN_DISTANCE = MIN_DISTANCE)
lims, D, I, hash_vectors = compare_videos(hash_vectors, target_indices, MIN_DISTANCE = MIN_DISTANCE)
fig = plot_comparison(lims, D, I, hash_vectors, MIN_DISTANCE = MIN_DISTANCE)
return fig
def get_auto_comparison(url, target, smoothing_window_size=10, method="CUSUM"):
""" Function for Gradio to combine all helper functions"""
distance = get_decent_distance(url, target, MIN_DISTANCE, MAX_DISTANCE)
if distance == None:
return None
raise gr.Error("No matches found!")
video_index, hash_vectors, target_indices = get_video_indices(url, target, MIN_DISTANCE = distance)
lims, D, I, hash_vectors = compare_videos(hash_vectors, target_indices, MIN_DISTANCE = distance)
# fig = plot_comparison(lims, D, I, hash_vectors, MIN_DISTANCE = distance)
df = get_videomatch_df(url, target, min_distance=MIN_DISTANCE, vanilla_df=False)
change_points = get_change_points(df, smoothing_window_size=smoothing_window_size, method=method)
fig = plot_multi_comparison(df, change_points)
return fig
def get_auto_edit_decision(url, target, smoothing_window_size=10):
""" Function for Gradio to combine all helper functions"""
distance = get_decent_distance(url, target, MIN_DISTANCE, MAX_DISTANCE)
if distance == None:
return None
raise gr.Error("No matches found!")
video_index, hash_vectors, target_indices = get_video_indices(url, target, MIN_DISTANCE = distance)
lims, D, I, hash_vectors = compare_videos(hash_vectors, target_indices, MIN_DISTANCE = distance)
df = get_videomatch_df(url, target, min_distance=MIN_DISTANCE, vanilla_df=False)
change_points = get_change_points(df, smoothing_window_size=smoothing_window_size, method="ROBUST")
edit_decision_list = []
for cp in change_points:
decision = f"Video at time {cp.start_time} returns {cp.metric}"
# edit_decision_list.append(f"Video at time {cp.start_time} returns {cp.metric}")
fig = plot_multi_comparison(df, change_points)
return fig
video_urls = ["https://www.dropbox.com/s/8c89a9aba0w8gjg/Ploumen.mp4?dl=1",
"https://www.dropbox.com/s/rzmicviu1fe740t/Bram%20van%20Ojik%20krijgt%20reprimande.mp4?dl=1",
"https://www.dropbox.com/s/wcot34ldmb84071/Baudet%20ontmaskert%20Omtzigt_%20u%20bent%20door%20de%20mand%20gevallen%21.mp4?dl=1",
"https://drive.google.com/uc?id=1XW0niHR1k09vPNv1cp6NvdGXe7FHJc1D&export=download",
"https://www.dropbox.com/s/4ognq8lshcujk43/Plenaire_zaal_20200923132426_Omtzigt.mp4?dl=1"]
index_iface = gr.Interface(fn=lambda url: index_hashes_for_video(url).ntotal,
inputs="text",
outputs="text",
examples=video_urls, cache_examples=True)
compare_iface = gr.Interface(fn=get_comparison,
inputs=["text", "text", gr.Slider(2, 30, 4, step=2)],
outputs="plot",
examples=[[x, video_urls[-1]] for x in video_urls[:-1]])
auto_compare_iface = gr.Interface(fn=get_auto_comparison,
inputs=["text", "text", gr.Slider(1, 50, 10, step=1), gr.Dropdown(choices=["CUSUM", "Robust"], value="Robust")],
outputs="plot",
examples=[[x, video_urls[-1]] for x in video_urls[:-1]])
iface = gr.TabbedInterface([auto_compare_iface, compare_iface, index_iface,], ["AutoCompare", "Compare", "Index"])
if __name__ == "__main__":
import matplotlib
matplotlib.use('SVG') # To be able to plot in gradio
iface.launch(show_error=True)
#iface.launch(auth=("test", "test"), share=True, debug=True) |