Spaces:
Running
Running
using hf datasets for videos
Browse files- app.py +20 -16
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
import csv
|
2 |
import os
|
|
|
3 |
import random
|
4 |
import sys
|
5 |
-
import pickle
|
6 |
from collections import Counter
|
7 |
from glob import glob
|
8 |
|
@@ -10,23 +10,17 @@ import clip
|
|
10 |
import gdown
|
11 |
import gradio as gr
|
12 |
import numpy as np
|
|
|
13 |
import torch
|
14 |
import torchvision
|
|
|
15 |
from tqdm import tqdm
|
16 |
|
17 |
from SimSearch import FaissCosineNeighbors
|
18 |
|
19 |
csv.field_size_limit(sys.maxsize)
|
20 |
|
21 |
-
|
22 |
-
# DOWNLOAD THE DATASET and Files
|
23 |
-
gdown.cached_download(
|
24 |
-
url="https://static.taesiri.com/gamephysics/GTAV-Videos.zip",
|
25 |
-
path="./GTAV-Videos.zip",
|
26 |
-
quiet=False,
|
27 |
-
md5="e961093bc032f579de060ed65564b4c3",
|
28 |
-
)
|
29 |
-
|
30 |
gdown.cached_download(
|
31 |
url="https://static.taesiri.com/gamephysics/mini-GTA-V-Embeddings.zip",
|
32 |
path="./GTA-V-Embeddings.zip",
|
@@ -34,10 +28,6 @@ gdown.cached_download(
|
|
34 |
md5="b1228503d5a89eef7e35e2cbf86b2fc0",
|
35 |
)
|
36 |
|
37 |
-
# EXTRACT
|
38 |
-
torchvision.datasets.utils.extract_archive(
|
39 |
-
from_path="GTAV-Videos.zip", to_path="Videos/", remove_finished=False
|
40 |
-
)
|
41 |
# EXTRACT
|
42 |
torchvision.datasets.utils.extract_archive(
|
43 |
from_path="GTA-V-Embeddings.zip",
|
@@ -45,9 +35,23 @@ torchvision.datasets.utils.extract_archive(
|
|
45 |
remove_finished=False,
|
46 |
)
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
# Initialize CLIP model
|
49 |
clip.available_models()
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
# # Searcher
|
52 |
class GamePhysicsSearcher:
|
53 |
def __init__(self, CLIP_MODEL, GAME_NAME, EMBEDDING_PATH="./Embeddings/VIT32/"):
|
@@ -113,8 +117,7 @@ class GamePhysicsSearcher:
|
|
113 |
topKs = list(self.f7(nearest_data_points[0]))[:k]
|
114 |
|
115 |
video_filename = [
|
116 |
-
|
117 |
-
+ self.class_id_to_file[x].replace("npy", "mp4")
|
118 |
for x in topKs
|
119 |
]
|
120 |
|
@@ -239,4 +242,5 @@ def main():
|
|
239 |
|
240 |
|
241 |
if __name__ == "__main__":
|
|
|
242 |
main()
|
|
|
1 |
import csv
|
2 |
import os
|
3 |
+
import pickle
|
4 |
import random
|
5 |
import sys
|
|
|
6 |
from collections import Counter
|
7 |
from glob import glob
|
8 |
|
|
|
10 |
import gdown
|
11 |
import gradio as gr
|
12 |
import numpy as np
|
13 |
+
import psutil
|
14 |
import torch
|
15 |
import torchvision
|
16 |
+
from datasets import load_dataset
|
17 |
from tqdm import tqdm
|
18 |
|
19 |
from SimSearch import FaissCosineNeighbors
|
20 |
|
21 |
csv.field_size_limit(sys.maxsize)
|
22 |
|
23 |
+
# Download Embeddings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
gdown.cached_download(
|
25 |
url="https://static.taesiri.com/gamephysics/mini-GTA-V-Embeddings.zip",
|
26 |
path="./GTA-V-Embeddings.zip",
|
|
|
28 |
md5="b1228503d5a89eef7e35e2cbf86b2fc0",
|
29 |
)
|
30 |
|
|
|
|
|
|
|
|
|
31 |
# EXTRACT
|
32 |
torchvision.datasets.utils.extract_archive(
|
33 |
from_path="GTA-V-Embeddings.zip",
|
|
|
35 |
remove_finished=False,
|
36 |
)
|
37 |
|
38 |
+
# Load videos from Dataset
|
39 |
+
gta_v_videos = load_dataset("taesiri/GamePhysics_Grand_Theft_Auto_V")
|
40 |
+
post_id_to_video_path = {
|
41 |
+
os.path.splitext(os.path.basename(x))[0]: x
|
42 |
+
for x in gta_v_videos["Grand_Theft_Auto_V"][:]["video_file_path"]
|
43 |
+
}
|
44 |
# Initialize CLIP model
|
45 |
clip.available_models()
|
46 |
|
47 |
+
|
48 |
+
# Log runtime environment info
|
49 |
+
def log_runtime_information():
|
50 |
+
print(f"CPU Count: {psutil.cpu_count()}")
|
51 |
+
print(f"Virtual Memory: {psutil.virtual_memory()}")
|
52 |
+
print(f"Swap Memory: {psutil.swap_memory()}")
|
53 |
+
|
54 |
+
|
55 |
# # Searcher
|
56 |
class GamePhysicsSearcher:
|
57 |
def __init__(self, CLIP_MODEL, GAME_NAME, EMBEDDING_PATH="./Embeddings/VIT32/"):
|
|
|
117 |
topKs = list(self.f7(nearest_data_points[0]))[:k]
|
118 |
|
119 |
video_filename = [
|
120 |
+
post_id_to_video_path[self.class_id_to_file[x].replace(".npy", "")]
|
|
|
121 |
for x in topKs
|
122 |
]
|
123 |
|
|
|
242 |
|
243 |
|
244 |
if __name__ == "__main__":
|
245 |
+
log_runtime_information()
|
246 |
main()
|
requirements.txt
CHANGED
@@ -59,4 +59,5 @@ typing_extensions==4.0.1
|
|
59 |
urllib3==1.26.8
|
60 |
wcwidth==0.2.5
|
61 |
Werkzeug==2.0.2
|
|
|
62 |
gdown
|
|
|
59 |
urllib3==1.26.8
|
60 |
wcwidth==0.2.5
|
61 |
Werkzeug==2.0.2
|
62 |
+
psuti==5.9.1
|
63 |
gdown
|