PedroMartelleto commited on
Commit
e5ab635
·
1 Parent(s): a779468

final commit?

Browse files
Files changed (5) hide show
  1. .gitignore +0 -1
  2. get_results.py +87 -0
  3. get_vimeo.py +43 -0
  4. rename_videos_vimeo.py +72 -0
  5. results.csv +7 -0
.gitignore CHANGED
@@ -1,3 +1,2 @@
1
  *.json
2
  .env
3
- *vimeo*.py
 
1
  *.json
2
  .env
 
get_results.py CHANGED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random
3
+ import firebase_admin
4
+ from firebase_admin import credentials
5
+ from firebase_admin import firestore
6
+ import uuid
7
+ import json
8
+ import os
9
+ from dotenv import load_dotenv
10
+ import re
11
+ import pandas as pd
12
+ from tqdm import tqdm
13
+
14
+ load_dotenv()
15
+
16
+ video_pairs = pd.read_csv('file_pairs.csv')[['file_name', 'vista_id', 'gem_id']].values.tolist()
17
+
18
+ my_credentials = {
19
+ "type": "service_account",
20
+ "project_id": "human-eval-c4f83",
21
+ "private_key_id": os.environ.get("PRIVATE_KEY_ID"),
22
+ "private_key": os.environ.get("PRIVATE_KEY").replace(r'\n', '\n'),
23
+ "client_email": os.environ.get("CLIENT_EMAIL"),
24
+ "client_id": os.environ.get("CLIENT_ID"),
25
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
26
+ "token_uri": "https://oauth2.googleapis.com/token",
27
+ "auth_provider_x509_cert_url": os.environ.get("AUTH_PROVIDER_X509_CERT_URL"),
28
+ "client_x509_cert_url": os.environ.get("CLIENT_X509_CERT_URL")
29
+ }
30
+
31
+ if not firebase_admin._apps:
32
+ cred = credentials.Certificate(my_credentials)
33
+ firebase_admin.initialize_app(cred)
34
+
35
+ db = firestore.client()
36
+ # get all votes
37
+ votes = db.collection('votes').get()
38
+
39
+ gem_vote_count = {}
40
+ vista_vote_count = {}
41
+ no_preference_count = {}
42
+
43
+ qids = [
44
+ 'realistic_dynamics',
45
+ 'visual_quality',
46
+ 'temporal_consistency',
47
+ ]
48
+
49
+ for vote in tqdm(votes):
50
+ vote_dict = vote.to_dict()
51
+ is_long = 'LONG' in vote_dict['video_name']
52
+
53
+ for qid in qids:
54
+ category = qid + ('_long' if is_long else '_short')
55
+ if category not in gem_vote_count:
56
+ gem_vote_count[category] = 0
57
+ vista_vote_count[category] = 0
58
+ no_preference_count[category] = 0
59
+
60
+ if vote_dict[qid] == 'Video 1' and vote_dict['video1_id'] == vote_dict['gem_id']:
61
+ gem_vote_count[category] += 1
62
+ elif vote_dict[qid] == 'Video 1' and vote_dict['video1_id'] == vote_dict['vista_id']:
63
+ vista_vote_count[category] += 1
64
+ elif vote_dict[qid] == 'Video 2' and vote_dict['video2_id'] == vote_dict['gem_id']:
65
+ gem_vote_count[category] += 1
66
+ elif vote_dict[qid] == 'Video 2' and vote_dict['video2_id'] == vote_dict['vista_id']:
67
+ vista_vote_count[category] += 1
68
+ elif vote_dict[qid] == 'No preference':
69
+ no_preference_count[category] += 1
70
+ else:
71
+ raise ValueError('Invalid vote: ' + str(vote_dict))
72
+
73
+ # Create a table with the results. One row for GEM, one row for Vista, one row for no preference
74
+
75
+ data = []
76
+ for qid in qids:
77
+ for is_long in [True, False]:
78
+ category = qid + ('_long' if is_long else '_short')
79
+ data.append({
80
+ 'category': category,
81
+ 'gem': gem_vote_count[category],
82
+ 'vista': vista_vote_count[category],
83
+ 'no_preference': no_preference_count[category]
84
+ })
85
+
86
+ df = pd.DataFrame(data)
87
+ df.to_csv('results.csv', index=False)
get_vimeo.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import vimeo
2
+ import pandas as pd
3
+ from dotenv import load_dotenv
4
+ import os
5
+ load_dotenv()
6
+
7
+ v = vimeo.VimeoClient(
8
+ token=os.environ.get("VIMEO_TOKEN"),
9
+ key=os.environ.get("VIMEO_KEY"),
10
+ secret=os.environ.get("VIMEO_SECRET")
11
+ )
12
+
13
+ user_id = 'pedrombr' # Replace with the actual user ID
14
+ endpoint = f'/users/{user_id}/videos'
15
+ # Make the GET request
16
+ response1 = v.get(f'{endpoint}?per_page=100').json()
17
+ response2 = v.get(f'{endpoint}?per_page=100&page=2').json()
18
+
19
+ response = response1
20
+ response['data'].extend(response2['data'])
21
+
22
+ gem_videos = [
23
+ ("_".join(v['name'].split("_")[1:]), v['uri'].split("/")[-1]) for v in response['data'] if v['name'].startswith('GEM')
24
+ ]
25
+
26
+ vista_videos = [
27
+ ("_".join(v['name'].split("_")[1:]), v['uri'].split("/")[-1]) for v in response['data'] if v['name'].startswith('Vista')
28
+ ]
29
+
30
+ assert len(gem_videos) == len(vista_videos) and len(gem_videos) == 99
31
+
32
+ # Match files by title and create a csv
33
+ data = []
34
+
35
+ for vista_file in vista_videos:
36
+ for gem_file in gem_videos:
37
+ if vista_file[0] == gem_file[0]:
38
+ data.append((vista_file[0], vista_file[1], gem_file[1]))
39
+
40
+ # sort by file_name
41
+ data.sort(key=lambda x: x[0])
42
+ df = pd.DataFrame(data, columns=['file_name', 'vista_id', 'gem_id'])
43
+ df.to_csv('file_pairs.csv', index=False)
rename_videos_vimeo.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import vimeo
2
+ from tqdm import tqdm
3
+ import time
4
+ from dotenv import load_dotenv
5
+ import os
6
+ load_dotenv()
7
+
8
+ v = vimeo.VimeoClient(
9
+ token=os.environ.get("VIMEO_TOKEN"),
10
+ key=os.environ.get("VIMEO_KEY"),
11
+ secret=os.environ.get("VIMEO_SECRET")
12
+ )
13
+
14
+ user_id = 'pedrombr' # Replace with the actual user ID
15
+ endpoint = f'/users/{user_id}/videos'
16
+ # Make the GET request
17
+ response1 = v.get(f'{endpoint}?per_page=100').json()
18
+ response2 = v.get(f'{endpoint}?per_page=100&page=2').json()
19
+
20
+ response = response1
21
+ response['data'].extend(response2['data'])
22
+
23
+ def rename_video(video_id):
24
+ try:
25
+ # Get the current video details
26
+ video_response = v.get(f"/videos/{video_id}")
27
+
28
+ if video_response.status_code != 200:
29
+ print(f"Failed to fetch video details: {video_response.json()}")
30
+ return
31
+
32
+ video_data = video_response.json()
33
+ current_name = video_data.get("name", "")
34
+
35
+ # Check if the name starts with 'GEM_'
36
+ if current_name.startswith("GEM_"):
37
+ new_name = current_name.replace("GEM_", f"{video_id}_", 1) # Remove the 'GEM_' prefix
38
+ # Update the video's name
39
+ patch_data = {"name": new_name}
40
+ response = v.patch(f"/videos/{video_id}", data=patch_data)
41
+
42
+ if response.status_code == 200:
43
+ print(f"Video renamed successfully to: {new_name}")
44
+ else:
45
+ print(f"Failed to rename video: {response.json()}")
46
+ elif current_name.startswith("Vista_"):
47
+ new_name = current_name.replace("Vista_", f"{video_id}_", 1)
48
+ patch_data = {"name": new_name}
49
+ response = v.patch(f"/videos/{video_id}", data=patch_data)
50
+ if response.status_code == 200:
51
+ print(f"Video renamed successfully to: {new_name}")
52
+ else:
53
+ print(f"Failed to rename video: {response.json()}")
54
+ else:
55
+ print("The video name does not start with 'GEM_' or 'Vista_'. No changes made.")
56
+ except Exception as e:
57
+ print(f"An error occurred: {e}")
58
+ time.sleep(60) # Wait for 60 seconds before retrying
59
+ rename_video(video_id) # Retry the operation
60
+
61
+ gem_videos = [
62
+ ("_".join(v['name'].split("_")[1:]), v['uri'].split("/")[-1]) for v in response['data'] if v['name'].startswith('GEM')
63
+ ]
64
+
65
+ vista_videos = [
66
+ ("_".join(v['name'].split("_")[1:]), v['uri'].split("/")[-1]) for v in response['data'] if v['name'].startswith('Vista')
67
+ ]
68
+
69
+ # assert len(gem_videos) == len(vista_videos) and len(gem_videos) == 99
70
+
71
+ for video in gem_videos + vista_videos:
72
+ rename_video(video[1]) # Pass the video ID to the rename function
results.csv ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ category,gem,vista,no_preference
2
+ realistic_dynamics_long,75,23,18
3
+ realistic_dynamics_short,35,26,76
4
+ visual_quality_long,79,29,8
5
+ visual_quality_short,38,51,48
6
+ temporal_consistency_long,81,27,8
7
+ temporal_consistency_short,41,36,60