Spaces:
Runtime error
Runtime error
Pushes the app file
Browse files
app.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Demo to show clips from AudioSet with Doppler effect."""
|
| 2 |
+
import os
|
| 3 |
+
from os.path import join, exists, dirname, abspath, basename
|
| 4 |
+
import json
|
| 5 |
+
from glob import glob
|
| 6 |
+
|
| 7 |
+
from tqdm import tqdm
|
| 8 |
+
import numpy as np
|
| 9 |
+
import pandas as pd
|
| 10 |
+
import streamlit as st
|
| 11 |
+
import matplotlib.pyplot as plt
|
| 12 |
+
# from moviepy.video.io.VideoFileClip import VideoFileClip
|
| 13 |
+
|
| 14 |
+
import warnings
|
| 15 |
+
warnings.simplefilter(action='ignore')
|
| 16 |
+
|
| 17 |
+
curr_filepath = abspath(__file__)
|
| 18 |
+
repo_path = dirname(dirname(curr_filepath))
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def make_grid(cols,rows):
|
| 22 |
+
grid = [0]*cols
|
| 23 |
+
for i in range(cols):
|
| 24 |
+
with st.container():
|
| 25 |
+
grid[i] = st.columns(rows)
|
| 26 |
+
return grid
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# Filter out samples with (possible) Doppler effect
|
| 30 |
+
doppler_classes = [
|
| 31 |
+
'airplane',
|
| 32 |
+
'ambulance siren',
|
| 33 |
+
# 'race car, auto racing', # Typically captured from within the car
|
| 34 |
+
'subway, metro, underground',
|
| 35 |
+
'car passing by',
|
| 36 |
+
# 'motorboat, speedboat acceleration', # Typically captured from within the boat
|
| 37 |
+
'railroad car, train wagon',
|
| 38 |
+
# 'helicopter',
|
| 39 |
+
# 'driving snowmobile', # Typically captured from within the snowmobile
|
| 40 |
+
'airplane flyby',
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
|
| 45 |
+
# Streamlit app code
|
| 46 |
+
st.set_page_config(layout="wide")
|
| 47 |
+
st.title("Clips from VGGSound (possibly with Doppler effect) 🎬")
|
| 48 |
+
|
| 49 |
+
# load data
|
| 50 |
+
if "df" not in st.session_state:
|
| 51 |
+
csv_path = "./data/vggsound.csv"
|
| 52 |
+
df = pd.read_csv(csv_path)
|
| 53 |
+
df.columns = ["video_id", "start_seconds", "label", "split"]
|
| 54 |
+
df["end_seconds"] = df["start_seconds"] + 10.
|
| 55 |
+
df = df[df["label"].isin(doppler_classes)]
|
| 56 |
+
st.session_state.df = df
|
| 57 |
+
else:
|
| 58 |
+
df = st.session_state.df
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
st.markdown(f"**Total number of relevant clips**: {len(df)}", unsafe_allow_html=True)
|
| 62 |
+
# st.markdown("---")
|
| 63 |
+
|
| 64 |
+
# # plot histogram
|
| 65 |
+
# arr = np.random.normal(1, 1, size=100)
|
| 66 |
+
# fig, ax = plt.subplots(1, 1, figsize=(1, 1))
|
| 67 |
+
# ax.hist(arr, bins=20)
|
| 68 |
+
# st.pyplot(fig)
|
| 69 |
+
|
| 70 |
+
# plot st bar chart
|
| 71 |
+
st.markdown("**Distribution of classes**")
|
| 72 |
+
count_df = df["label"].value_counts().reset_index()
|
| 73 |
+
# sort by count
|
| 74 |
+
count_df = count_df.sort_values(by="label", ascending=False)
|
| 75 |
+
print(count_df)
|
| 76 |
+
st.bar_chart(count_df, width=300, height=0)
|
| 77 |
+
|
| 78 |
+
reload_button = st.button("Reload")
|
| 79 |
+
NUM = 9
|
| 80 |
+
indices = np.random.randint(0, len(st.session_state.df), NUM)
|
| 81 |
+
if reload_button:
|
| 82 |
+
indices = np.random.randint(0, len(st.session_state.df), NUM)
|
| 83 |
+
|
| 84 |
+
videoids = []
|
| 85 |
+
segments = []
|
| 86 |
+
labels = []
|
| 87 |
+
for index in indices:
|
| 88 |
+
sample = st.session_state.df.iloc[index].to_dict()
|
| 89 |
+
video_id = sample["video_id"]
|
| 90 |
+
videoids.append(video_id)
|
| 91 |
+
start_time = sample["start_seconds"]
|
| 92 |
+
end_time = sample["end_seconds"]
|
| 93 |
+
segments.append((start_time, end_time))
|
| 94 |
+
labels.append(sample["label"])
|
| 95 |
+
|
| 96 |
+
# st.markdown(f"Showing Foley segments from a clip in movie: **{video_id}**")
|
| 97 |
+
# Create a grid of videos
|
| 98 |
+
grid = make_grid(3, 3)
|
| 99 |
+
per_video_width = 360
|
| 100 |
+
per_video_height = 240
|
| 101 |
+
|
| 102 |
+
# Add videos to the grid
|
| 103 |
+
for idx in range(0, min(len(segments), 9)):
|
| 104 |
+
i, j = idx // 3, idx % 3
|
| 105 |
+
|
| 106 |
+
start, end = segments[idx]
|
| 107 |
+
duration = end - start
|
| 108 |
+
video_id = videoids[idx]
|
| 109 |
+
|
| 110 |
+
grid[i][j].caption(f"Segment duration: {duration}")
|
| 111 |
+
url = f"https://www.youtube.com/embed/{video_id}?start={int(start)}&end={int(end)}"
|
| 112 |
+
html_code = f"""
|
| 113 |
+
<iframe height="{per_video_height}" width="{per_video_width}" src="{url}" frameborder="0" allowfullscreen></iframe>
|
| 114 |
+
"""
|
| 115 |
+
grid[i][j].markdown(html_code, unsafe_allow_html=True)
|
| 116 |
+
grid[i][j].caption(f"{labels[idx]}")
|
| 117 |
+
|
| 118 |
+
|