Spaces:
Sleeping
Sleeping
beweinreich
commited on
Commit
•
f8f47d0
1
Parent(s):
a5eba26
ok
Browse files- requirements.txt +2 -2
- video_analyzer.py +11 -8
requirements.txt
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
fastapi==0.111.1
|
|
|
2 |
moviepy==1.0.3
|
3 |
-
transformers==4.42.4
|
4 |
openai==1.34.0
|
5 |
python-dotenv==1.0.1
|
6 |
torch==2.3.1
|
7 |
transformers==4.42.4
|
8 |
-
uvicorn==0.30.3
|
|
|
1 |
fastapi==0.111.1
|
2 |
+
imageio==2.34.1
|
3 |
moviepy==1.0.3
|
|
|
4 |
openai==1.34.0
|
5 |
python-dotenv==1.0.1
|
6 |
torch==2.3.1
|
7 |
transformers==4.42.4
|
8 |
+
uvicorn==0.30.3
|
video_analyzer.py
CHANGED
@@ -5,6 +5,7 @@ import requests
|
|
5 |
from tqdm import tqdm
|
6 |
from dotenv import load_dotenv
|
7 |
from moviepy.editor import VideoFileClip
|
|
|
8 |
import re
|
9 |
import urllib.request
|
10 |
|
@@ -28,7 +29,7 @@ class VideoAnalyzer:
|
|
28 |
self.download_video()
|
29 |
|
30 |
def download_video(self):
|
31 |
-
self.video_path = "./tmp/video.
|
32 |
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
|
33 |
password_mgr.add_password(None, self.video_url, TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
|
34 |
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
|
@@ -37,13 +38,16 @@ class VideoAnalyzer:
|
|
37 |
urllib.request.urlretrieve(self.video_url, self.video_path)
|
38 |
|
39 |
def extract_images(self):
|
40 |
-
|
41 |
-
duration =
|
42 |
-
|
|
|
|
|
43 |
self.image_filenames = [f"./tmp/image_{i}.jpg" for i in range(self.num_images)]
|
44 |
|
45 |
-
for i,
|
46 |
-
|
|
|
47 |
|
48 |
def encode_image(self, image_path):
|
49 |
with open(image_path, "rb") as image_file:
|
@@ -107,8 +111,7 @@ class VideoAnalyzer:
|
|
107 |
|
108 |
if __name__ == "__main__":
|
109 |
# Use either video_path or video_url
|
110 |
-
|
111 |
-
video_url = "https://video.twilio.com/v1/Recordings/RT2c1baf50b6343802964c98e5a6f979e3/Media"
|
112 |
analyzer = VideoAnalyzer(video_url=video_url)
|
113 |
traits = analyzer.retrieve_traits()
|
114 |
print(traits)
|
|
|
5 |
from tqdm import tqdm
|
6 |
from dotenv import load_dotenv
|
7 |
from moviepy.editor import VideoFileClip
|
8 |
+
import imageio
|
9 |
import re
|
10 |
import urllib.request
|
11 |
|
|
|
29 |
self.download_video()
|
30 |
|
31 |
def download_video(self):
|
32 |
+
self.video_path = "./tmp/video.mkv"
|
33 |
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
|
34 |
password_mgr.add_password(None, self.video_url, TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
|
35 |
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
|
|
|
38 |
urllib.request.urlretrieve(self.video_url, self.video_path)
|
39 |
|
40 |
def extract_images(self):
|
41 |
+
reader = imageio.get_reader(self.video_path, 'ffmpeg')
|
42 |
+
duration = reader.get_meta_data()['duration']
|
43 |
+
fps = reader.get_meta_data()['fps']
|
44 |
+
num_frames = int(duration * fps)
|
45 |
+
frame_indices = [int(i * (num_frames / (self.num_images + 1))) for i in range(1, self.num_images + 1)]
|
46 |
self.image_filenames = [f"./tmp/image_{i}.jpg" for i in range(self.num_images)]
|
47 |
|
48 |
+
for i, frame_idx in enumerate(frame_indices):
|
49 |
+
frame = reader.get_data(frame_idx)
|
50 |
+
imageio.imwrite(self.image_filenames[i], frame)
|
51 |
|
52 |
def encode_image(self, image_path):
|
53 |
with open(image_path, "rb") as image_file:
|
|
|
111 |
|
112 |
if __name__ == "__main__":
|
113 |
# Use either video_path or video_url
|
114 |
+
video_url = "https://video.twilio.com/v1/Recordings/RTd8f67290c5665868602625bec14518e5/Media"
|
|
|
115 |
analyzer = VideoAnalyzer(video_url=video_url)
|
116 |
traits = analyzer.retrieve_traits()
|
117 |
print(traits)
|