Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import login
|
3 |
-
from transformers import
|
4 |
import torch
|
5 |
|
6 |
# Load the Hugging Face API token from environment variables or enter directly
|
7 |
# HUGGINGFACEHUB_API_TOKEN = "your_huggingface_api_token"
|
8 |
# login(HUGGINGFACEHUB_API_TOKEN)
|
9 |
|
10 |
-
# Define the model and
|
11 |
-
model_name = "microsoft/xclip-base-patch32"
|
|
|
12 |
model = AutoModelForVideoClassification.from_pretrained(model_name)
|
13 |
-
|
14 |
|
15 |
# Create a video classification pipeline
|
16 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
17 |
model.to(device)
|
18 |
|
19 |
-
|
20 |
|
21 |
# Define the function for video classification
|
22 |
def classify_video(video_path):
|
23 |
-
predictions =
|
24 |
-
return predictions
|
25 |
|
26 |
# Create a Gradio interface
|
27 |
interface = gr.Interface(
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import login
|
3 |
+
from transformers import AutoModelForVideoClassification, AutoFeatureExtractor, pipeline
|
4 |
import torch
|
5 |
|
6 |
# Load the Hugging Face API token from environment variables or enter directly
|
7 |
# HUGGINGFACEHUB_API_TOKEN = "your_huggingface_api_token"
|
8 |
# login(HUGGINGFACEHUB_API_TOKEN)
|
9 |
|
10 |
+
# Define the model and feature extractor from Hugging Face
|
11 |
+
# model_name = "microsoft/xclip-base-patch32"
|
12 |
+
model_name = "facebook/timesformer-base-finetuned-k400"
|
13 |
model = AutoModelForVideoClassification.from_pretrained(model_name)
|
14 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
|
15 |
|
16 |
# Create a video classification pipeline
|
17 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
18 |
model.to(device)
|
19 |
|
20 |
+
video_pipeline = pipeline("video-classification", model=model, feature_extractor=feature_extractor, device=0 if torch.cuda.is_available() else -1)
|
21 |
|
22 |
# Define the function for video classification
|
23 |
def classify_video(video_path):
|
24 |
+
predictions = video_pipeline(video_path)
|
25 |
+
return {prediction['label']: prediction['score'] for prediction in predictions}
|
26 |
|
27 |
# Create a Gradio interface
|
28 |
interface = gr.Interface(
|