bpiyush commited on
Commit
333db0f
·
1 Parent(s): fbc20a4

Adds app.py file

Browse files
Files changed (1) hide show
  1. app.py +85 -0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # from moviepy.video.io.VideoFileClip import VideoFileClip
12
+
13
+ import warnings
14
+ warnings.simplefilter(action='ignore')
15
+
16
+ curr_filepath = abspath(__file__)
17
+ repo_path = dirname(dirname(curr_filepath))
18
+
19
+
20
+ def make_grid(cols,rows):
21
+ grid = [0]*cols
22
+ for i in range(cols):
23
+ with st.container():
24
+ grid[i] = st.columns(rows)
25
+ return grid
26
+
27
+
28
+ if __name__ == "__main__":
29
+
30
+ # Streamlit app code
31
+ st.set_page_config(layout="wide")
32
+ st.title("Clips from AudioSet (possibly with Doppler effect) 🎬")
33
+
34
+ # load data
35
+ if "df" not in st.session_state:
36
+ csv_path = "./data/audioset_all_v1.csv"
37
+ # df = pd.read_csv(csv_path, skiprows=2, sep=", ", engine='python')
38
+ df = pd.read_csv(csv_path)
39
+ st.session_state.df = df
40
+ else:
41
+ df = st.session_state.df
42
+
43
+ print(df)
44
+ st.markdown(f"**Total number of relevant clips**: {len(df)}", unsafe_allow_html=True)
45
+ # st.markdown("---")
46
+
47
+ reload_button = st.button("Reload")
48
+ NUM = 9
49
+ indices = np.random.randint(0, len(st.session_state.df), NUM)
50
+ if reload_button:
51
+ indices = np.random.randint(0, len(st.session_state.df), NUM)
52
+
53
+ videoids = []
54
+ segments = []
55
+ for index in indices:
56
+ sample = st.session_state.df.iloc[index].to_dict()
57
+ video_id = sample["# YTID"]
58
+ videoids.append(video_id)
59
+ start_time = sample["start_seconds"]
60
+ end_time = sample["end_seconds"]
61
+ segments.append((start_time, end_time))
62
+
63
+ # st.markdown(f"Showing Foley segments from a clip in movie: **{video_id}**")
64
+ # Create a grid of videos
65
+ grid = make_grid(3, 3)
66
+ per_video_width = 360
67
+ per_video_height = 240
68
+
69
+ # Add videos to the grid
70
+ for idx in range(0, min(len(segments), 9)):
71
+ i, j = idx // 3, idx % 3
72
+
73
+ start, end = segments[idx]
74
+ duration = end - start
75
+ video_id = videoids[idx]
76
+
77
+ grid[i][j].caption(f"Segment duration: {duration}")
78
+ url = f"https://www.youtube.com/embed/{video_id}?start={int(start)}&end={int(end)}"
79
+ html_code = f"""
80
+ <iframe height="{per_video_height}" width="{per_video_width}" src="{url}" frameborder="0" allowfullscreen></iframe>
81
+ """
82
+ grid[i][j].markdown(html_code, unsafe_allow_html=True)
83
+ # grid[i][j].caption(f"{labels[idx]}")
84
+
85
+