import torch import os import gradio as gr from video_transformers import VideoModel from utils import ( convert_frames_to_gif, download_youtube_video, sample_frames_from_video_file, ) video_model = VideoModel.from_transformers("facebook/timesformer-base-finetuned-k400") examples = [ ["https://www.youtube.com/watch?v=huAJ9dC5lmI"], ["https://www.youtube.com/watch?v=wvcWt6u5HTg"], ["https://www.youtube.com/watch?v=-3kZSi5qjRM"], ["https://www.youtube.com/watch?v=-6usjfP8hys"], ["https://www.youtube.com/watch?v=BDHub0gBGtc"], ["https://www.youtube.com/watch?v=B9ea7YyCP6E"], ["https://www.youtube.com/watch?v=BBkpaeJBKmk"], ["https://www.youtube.com/watch?v=BBqU8Apee_g"], ["https://www.youtube.com/watch?v=B8OdMwVwyXc"], ["https://www.youtube.com/watch?v=I7cwq6_4QtM"], ["https://www.youtube.com/watch?v=Z0mJDXpNhYA"], ["https://www.youtube.com/watch?v=QkQQjFGnZlg"], ["https://www.youtube.com/watch?v=IQaoRUQif14"], ] def predict(youtube_url): video_path = download_youtube_video(youtube_url) frames = sample_frames_from_video_file(video_path, num_frames=16) gif_path = convert_frames_to_gif(frames) result = video_model.predict(video_or_folder_path=video_path) os.remove(video_path) return result["predictions"], gif_path app = gr.Blocks() with app: gr.Markdown("# **
Video Classification with Timesformer
**") gr.Markdown( """
Timesformer is a video model that uses a Transformer architecture to process video frames.
It is released by Facebook AI Research in ICML 2021.
This version is trained on Kinetics-400 dataset and can classify videos into 400 classes.
Follow me for more!
twitter | github | linkedin | medium