Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
import cv2 # OpenCV for video processing
|
| 4 |
|
| 5 |
# Model ID for video classification (UCF101 subset)
|
|
@@ -9,11 +9,19 @@ def analyze_video(video):
|
|
| 9 |
# Extract key frames from the video using OpenCV
|
| 10 |
frames = extract_key_frames(video)
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# Analyze key frames using video classification model
|
| 13 |
results = []
|
| 14 |
-
classifier = pipeline("video-classification", model=model_id)
|
| 15 |
for frame in frames:
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
# Analyze predictions for insights related to the play
|
| 18 |
result = analyze_predictions_ucf101(predictions)
|
| 19 |
results.append(result)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForVideoClassification, AutoTokenizer, VideoClassificationPipeline
|
| 3 |
import cv2 # OpenCV for video processing
|
| 4 |
|
| 5 |
# Model ID for video classification (UCF101 subset)
|
|
|
|
| 9 |
# Extract key frames from the video using OpenCV
|
| 10 |
frames = extract_key_frames(video)
|
| 11 |
|
| 12 |
+
# Load model and tokenizer manually
|
| 13 |
+
model = AutoModelForVideoClassification.from_pretrained(model_id)
|
| 14 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 15 |
+
|
| 16 |
+
# Create the pipeline
|
| 17 |
+
classifier = VideoClassificationPipeline(model=model, tokenizer=tokenizer, device=-1)
|
| 18 |
+
|
| 19 |
# Analyze key frames using video classification model
|
| 20 |
results = []
|
|
|
|
| 21 |
for frame in frames:
|
| 22 |
+
# OpenCV uses BGR, convert to RGB for the model
|
| 23 |
+
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 24 |
+
predictions = classifier(images=[frame_rgb]) # Assuming model outputs probabilities
|
| 25 |
# Analyze predictions for insights related to the play
|
| 26 |
result = analyze_predictions_ucf101(predictions)
|
| 27 |
results.append(result)
|