flocolombari
commited on
Commit
•
d4bf58f
1
Parent(s):
1bdad60
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,15 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
import cv2
|
|
|
|
|
4 |
|
5 |
def video_to_descriptions(video):
|
6 |
# Charger le modèle via pipeline
|
7 |
-
model = pipeline('
|
8 |
|
9 |
# Ouvrir la vidéo
|
10 |
-
cap = cv2.VideoCapture(video)
|
11 |
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
12 |
|
13 |
descriptions = []
|
@@ -22,8 +24,10 @@ def video_to_descriptions(video):
|
|
22 |
if frame_count % (fps // 2) == 0:
|
23 |
# Convertir l'image en RGB
|
24 |
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
|
|
|
|
25 |
# Obtenir la description de l'image
|
26 |
-
outputs = model(
|
27 |
description = outputs[0]['describe-text']
|
28 |
descriptions.append(description)
|
29 |
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
import cv2
|
4 |
+
from PIL import Image
|
5 |
+
import io
|
6 |
|
7 |
def video_to_descriptions(video):
|
8 |
# Charger le modèle via pipeline
|
9 |
+
model = pipeline('text2text-generation', model='nlpconnect/vit-gpt2-image-captioning')
|
10 |
|
11 |
# Ouvrir la vidéo
|
12 |
+
cap = cv2.VideoCapture(video.name)
|
13 |
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
14 |
|
15 |
descriptions = []
|
|
|
24 |
if frame_count % (fps // 2) == 0:
|
25 |
# Convertir l'image en RGB
|
26 |
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
27 |
+
# Convertir le tableau numpy en une image PIL
|
28 |
+
pil_img = Image.fromarray(frame_rgb)
|
29 |
# Obtenir la description de l'image
|
30 |
+
outputs = model(pil_img)
|
31 |
description = outputs[0]['describe-text']
|
32 |
descriptions.append(description)
|
33 |
|