File size: 732 Bytes
1ea578c
9fd7818
f7969de
9fd7818
10c5c1f
1ea578c
 
 
 
 
 
 
 
 
 
 
 
 
e38d732
9fd7818
e38d732
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from transformers import VideoMAEImageProcessor, VideoMAEForVideoClassification, pipeline
import gradio as gr
import magic

pipe = pipeline("video-classification", model="anirudhmu/videomae-base-finetuned-soccer-action-recognitionx2")


def predict_video(file_path):
    # Check the file type
    mime = magic.Magic(mime=True)
    file_type = mime.from_file(file_path)
    
    if not file_type.startswith('video/'):
        return "Invalid file type. Please upload a valid video."
    
    # Run inference
    results = pipe(file_path)
    label_to_score = {result["label"]: result["score"] for result in results}
    return str(label_to_score)

iface = gr.Interface(fn=predict_video, inputs="video", outputs="text")
iface.launch()