"""Demo to show clips from AudioSet with Doppler effect.""" import os from os.path import join, exists, dirname, abspath, basename import json from glob import glob from tqdm import tqdm import numpy as np import pandas as pd import streamlit as st # from moviepy.video.io.VideoFileClip import VideoFileClip import warnings warnings.simplefilter(action='ignore') curr_filepath = abspath(__file__) repo_path = dirname(dirname(curr_filepath)) def make_grid(cols,rows): grid = [0]*cols for i in range(cols): with st.container(): grid[i] = st.columns(rows) return grid if __name__ == "__main__": # Streamlit app code st.set_page_config(layout="wide") st.title("Clips from AudioSet (possibly with Doppler effect) 🎬") # load data if "df" not in st.session_state: csv_path = "./data/audioset_all_v1.csv" # df = pd.read_csv(csv_path, skiprows=2, sep=", ", engine='python') df = pd.read_csv(csv_path) st.session_state.df = df else: df = st.session_state.df print(df) st.markdown(f"**Total number of relevant clips**: {len(df)}", unsafe_allow_html=True) # st.markdown("---") reload_button = st.button("Reload") NUM = 9 indices = np.random.randint(0, len(st.session_state.df), NUM) if reload_button: indices = np.random.randint(0, len(st.session_state.df), NUM) videoids = [] segments = [] for index in indices: sample = st.session_state.df.iloc[index].to_dict() video_id = sample["# YTID"] videoids.append(video_id) start_time = sample["start_seconds"] end_time = sample["end_seconds"] segments.append((start_time, end_time)) # st.markdown(f"Showing Foley segments from a clip in movie: **{video_id}**") # Create a grid of videos grid = make_grid(3, 3) per_video_width = 360 per_video_height = 240 # Add videos to the grid for idx in range(0, min(len(segments), 9)): i, j = idx // 3, idx % 3 start, end = segments[idx] duration = end - start video_id = videoids[idx] grid[i][j].caption(f"Segment duration: {duration}") url = f"https://www.youtube.com/embed/{video_id}?start={int(start)}&end={int(end)}" html_code = f""" """ grid[i][j].markdown(html_code, unsafe_allow_html=True) # grid[i][j].caption(f"{labels[idx]}")