Spaces:
Build error
Build error
Adds app.py for AVTime dataset
Browse files
app.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Streamlit demo to visualize AVTime Dataset."""
|
| 2 |
+
import os
|
| 3 |
+
from os.path import join, exists, dirname, abspath, basename
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
import pandas as pd
|
| 7 |
+
import streamlit as st
|
| 8 |
+
|
| 9 |
+
import warnings
|
| 10 |
+
warnings.simplefilter(action='ignore')
|
| 11 |
+
|
| 12 |
+
curr_filepath = abspath(__file__)
|
| 13 |
+
repo_path = dirname(dirname(curr_filepath))
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def make_grid(cols,rows):
|
| 17 |
+
grid = [0]*cols
|
| 18 |
+
for i in range(cols):
|
| 19 |
+
with st.container():
|
| 20 |
+
grid[i] = st.columns(rows)
|
| 21 |
+
return grid
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def read_spreadsheet(sheet_id, gid, **kwargs):
|
| 25 |
+
BASE_URL = 'https://docs.google.com/spreadsheets/d/'
|
| 26 |
+
df = pd.read_csv(BASE_URL + sheet_id + f'/export?gid={gid}&format=csv', **kwargs)
|
| 27 |
+
# drop all rows which have atleast 1 NaN value
|
| 28 |
+
df = df.dropna(axis=0)
|
| 29 |
+
return df
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
SHEET_ID = "1ejT6SWbihrYzfB_npb0WS2UHd8TIxPZkMpqbJ-M_hfw"
|
| 33 |
+
GID = "0"
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
# Add a title
|
| 38 |
+
st.set_page_config(layout="wide")
|
| 39 |
+
st.title("Clips from AVTime Dataset 🎬")
|
| 40 |
+
|
| 41 |
+
if "df" not in st.session_state:
|
| 42 |
+
# Read spreadsheet
|
| 43 |
+
df = read_spreadsheet(sheet_id=SHEET_ID, gid=GID, on_bad_lines='skip')
|
| 44 |
+
st.session_state.df = df
|
| 45 |
+
else:
|
| 46 |
+
df = st.session_state.df
|
| 47 |
+
|
| 48 |
+
st.markdown(f"**Total number of relevant clips**: {len(df)}", unsafe_allow_html=True)
|
| 49 |
+
|
| 50 |
+
reload_button = st.button("Reload")
|
| 51 |
+
NUM = 9
|
| 52 |
+
indices = np.random.randint(0, len(st.session_state.df), NUM)
|
| 53 |
+
if reload_button:
|
| 54 |
+
indices = np.random.randint(0, len(st.session_state.df), NUM)
|
| 55 |
+
|
| 56 |
+
# Create a grid of videos
|
| 57 |
+
grid = make_grid(3, 3)
|
| 58 |
+
per_video_width = 360
|
| 59 |
+
per_video_height = 240
|
| 60 |
+
|
| 61 |
+
for idx, index in enumerate(indices):
|
| 62 |
+
sample = st.session_state.df.iloc[index].to_dict()
|
| 63 |
+
video_id = sample["video_id"]
|
| 64 |
+
stime, etime = sample["start_time"], sample["end_time"]
|
| 65 |
+
duration = etime - stime
|
| 66 |
+
desc = sample["description"]
|
| 67 |
+
|
| 68 |
+
i, j = idx // 3, idx % 3
|
| 69 |
+
grid[i][j].caption(f"Segment duration: {duration}")
|
| 70 |
+
url = f"https://www.youtube.com/embed/{video_id}?start={int(stime)}&end={int(etime)}"
|
| 71 |
+
html_code = f"""
|
| 72 |
+
<iframe height="{per_video_height}" width="{per_video_width}" src="{url}" frameborder="0" allowfullscreen></iframe>
|
| 73 |
+
"""
|
| 74 |
+
grid[i][j].markdown(html_code, unsafe_allow_html=True)
|
| 75 |
+
grid[i][j].caption(f"{desc}")
|