contact-eyes / app.py
mbesinci's picture
Create app.py
6226c23 verified
raw
history blame contribute delete
975 Bytes
import gradio as gr
from transformers import VideoMAEForVideoClassification, VideoMAEFeatureExtractor
import cv2
# Modeli ve özellik çıkarıcıyı yükleyin
model_name = "MCG-NJU/videomae-base-finetuned-kinetics"
model = VideoMAEForVideoClassification.from_pretrained(model_name)
feature_extractor = VideoMAEFeatureExtractor.from_pretrained(model_name)
# Video işleme ve sınıflandırma fonksiyonu
def classify_video(video):
cap = cv2.VideoCapture(video)
frames = []
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
frames.append(frame)
cap.release()
inputs = feature_extractor(frames, return_tensors="pt")
outputs = model(**inputs)
predicted_class = outputs.logits.argmax(-1).item()
return f"Predicted class: {predicted_class}"
# Gradio arayüzü kurma
demo = gr.Interface(
fn=classify_video,
inputs="file",
outputs="text",
title="Video Classifier"
)
demo.launch()