PedroMartelleto commited on
Commit
74020c7
·
1 Parent(s): e88f4b9
Files changed (5) hide show
  1. app.py +59 -43
  2. file_pairs.csv +31 -0
  3. get_drive.py +29 -0
  4. get_results.py +0 -0
  5. requirements.txt +2 -1
app.py CHANGED
@@ -8,14 +8,11 @@ import json
8
  import os
9
  from dotenv import load_dotenv
10
  import re
 
11
 
12
  load_dotenv()
13
 
14
- video_pairs = [
15
- ('1XCLpvcAPg8fUAZ7k5hdUbT9avNnf12t3', '1Nve35Qo3I4Oe6ANsdj78Uo-3EZJkf28P'),
16
- ('1bHfhebrflmGTksFlzTskOjQX28TM-yVb', '1-LwBNDp1mliDGYVnIb_cCERvyNFeC4bC'),
17
- ('1mlSxLm_9LeTKj-m03pGun-1eefX58aF_', '1x4j79qiBkzl-bgjSRddwWF4yTMm63tKC'),
18
- ]
19
 
20
  my_credentials = {
21
  "type": "service_account",
@@ -45,20 +42,23 @@ def get_video_pair(state):
45
  shuffled_pairs = state['shuffled_pairs']
46
  user_votes = state['user_votes']
47
  while pair_index < len(shuffled_pairs):
48
- video1_id, video2_id = shuffled_pairs[pair_index]
49
- pair_key = f"{video1_id}_{video2_id}"
50
  if pair_key not in user_votes:
51
  # Randomize left-right positions
52
  if random.choice([True, False]):
53
- left_video_id, right_video_id = video1_id, video2_id
54
  else:
55
- left_video_id, right_video_id = video2_id, video1_id
56
- left_video_url = get_embed_link(left_video_id)
57
- right_video_url = get_embed_link(right_video_id)
58
- state['left_video_id'] = left_video_id
59
- state['right_video_id'] = right_video_id
 
60
  state['video1_id'] = video1_id
61
  state['video2_id'] = video2_id
 
 
62
  return left_video_url, right_video_url
63
  else:
64
  pair_index += 1
@@ -66,15 +66,16 @@ def get_video_pair(state):
66
  return None, None # No more pairs
67
 
68
  def generate_video_html(url):
69
- return f'<iframe src="{url}" width="480" height="320" allow="autoplay"></iframe>'
70
 
71
- def save_vote(email, video1_id, video2_id, left_video_id, right_video_id, responses):
72
  vote_data = {
 
73
  'email': email,
74
- 'video1': video1_id,
75
- 'video2': video2_id,
76
- 'left_video': left_video_id,
77
- 'right_video': right_video_id,
78
  'visual_quality': responses['visual_quality'],
79
  'temporal_consistency': responses['temporal_consistency'],
80
  'realistic_dynamics': responses['realistic_dynamics'],
@@ -87,7 +88,7 @@ def save_vote(email, video1_id, video2_id, left_video_id, right_video_id, respon
87
  user_votes = set(user_doc.to_dict().get('votes', []))
88
  else:
89
  user_votes = set()
90
- pair_key = f"{video1_id}_{video2_id}"
91
  user_votes.add(pair_key)
92
  user_ref.set({'votes': list(user_votes)}, merge=True)
93
 
@@ -95,20 +96,21 @@ def update_interface(responses, state):
95
  email = state['email']
96
  user_votes = state['user_votes']
97
  pair_index = state['pair_index']
98
- left_video_id = state['left_video_id']
99
- right_video_id = state['right_video_id']
100
  video1_id = state['video1_id']
101
  video2_id = state['video2_id']
 
 
 
102
 
103
  # Save the user's responses
104
- save_vote(email, video1_id, video2_id, left_video_id, right_video_id, responses)
105
 
106
  # Update state
107
  pair_index += 1
108
  state['pair_index'] = pair_index
109
 
110
  # Update user_votes in state
111
- pair_key = f"{video1_id}_{video2_id}"
112
  user_votes.add(pair_key)
113
  state['user_votes'] = user_votes
114
 
@@ -117,7 +119,8 @@ def update_interface(responses, state):
117
  # No more pairs
118
  output_message = "Thank you for participating! No more videos."
119
  return (
120
- gr.update(visible=False), # video_row
 
121
  gr.update(value=""), # video1
122
  gr.update(value=""), # video2
123
  gr.update(visible=False), # question_column
@@ -134,7 +137,8 @@ def update_interface(responses, state):
134
  video2_html = generate_video_html(video2_url)
135
  # Update videos and reset questions
136
  return (
137
- gr.update(visible=True), # video_row
 
138
  gr.update(value=video1_html), # video1
139
  gr.update(value=video2_html), # video2
140
  gr.update(visible=True), # question_column
@@ -164,7 +168,8 @@ def authenticate_user(email, state):
164
  gr.update(), # email_input (remains visible)
165
  gr.update(), # submit_email (remains visible)
166
  "Please enter a valid email.", # email_output
167
- gr.update(visible=False), # video_row
 
168
  gr.update(value=""), # video1
169
  gr.update(value=""), # video2
170
  gr.update(visible=False), # question_column
@@ -200,7 +205,8 @@ def authenticate_user(email, state):
200
  gr.update(visible=False), # email_input
201
  gr.update(visible=False), # submit_email
202
  "", # email_output
203
- gr.update(visible=False), # video_row
 
204
  gr.update(value=""), # video1
205
  gr.update(value=""), # video2
206
  gr.update(visible=False), # question_column
@@ -215,7 +221,8 @@ def authenticate_user(email, state):
215
  gr.update(visible=False), # email_input
216
  gr.update(visible=False), # submit_email
217
  "", # email_output
218
- gr.update(visible=True), # video_row
 
219
  gr.update(value=video1_html), # video1
220
  gr.update(value=video2_html), # video2
221
  gr.update(visible=True), # question_column
@@ -227,36 +234,43 @@ def authenticate_user(email, state):
227
  with gr.Blocks() as demo:
228
  state = gr.State(value={})
229
 
 
 
 
 
 
 
 
230
  # Email Input
231
  email_input = gr.Textbox(label="Enter your email to begin:", placeholder="your.email@example.com", type="text")
232
  submit_email = gr.Button("Submit")
233
  email_output = gr.Markdown()
234
 
235
  # Video components (initially hidden)
236
- with gr.Row(visible=False) as video_row:
237
- with gr.Column():
238
- gr.Markdown("### Video 1")
239
- video1 = gr.HTML()
240
- with gr.Column():
241
- gr.Markdown("### Video 2")
242
- video2 = gr.HTML()
243
 
244
  # Questions (initially hidden)
245
  with gr.Column(visible=False) as question_column:
246
  gr.Markdown("## Please answer the following questions:")
247
  q1 = gr.Radio(
248
- choices=["Video 1", "Video 2"],
249
  label="1. Which video has higher visual quality?",
250
  type="value"
251
  )
252
  q2 = gr.Radio(
253
- choices=["Video 1", "Video 2"],
254
- label="2. Which video has better temporal consistency?",
255
  type="value"
256
  )
257
  q3 = gr.Radio(
258
- choices=["Video 1", "Video 2"],
259
- label="3. Which video has more realistic dynamics?",
260
  type="value"
261
  )
262
 
@@ -279,7 +293,8 @@ with gr.Blocks() as demo:
279
  fn=on_next,
280
  inputs=[q1, q2, q3, state],
281
  outputs=[
282
- video_row, # Update video_row
 
283
  video1, # Update video1
284
  video2, # Update video2
285
  question_column, # Update question_column
@@ -317,7 +332,8 @@ with gr.Blocks() as demo:
317
  email_input, # Update email_input
318
  submit_email, # Update submit_email
319
  email_output, # Update email_output
320
- video_row, # Update video_row
 
321
  video1, # Update video1
322
  video2, # Update video2
323
  question_column, # Update question_column
 
8
  import os
9
  from dotenv import load_dotenv
10
  import re
11
+ import pandas as pd
12
 
13
  load_dotenv()
14
 
15
+ video_pairs = pd.read_csv('file_pairs.csv')[['file_name', 'vista_id', 'gem_id']].values.tolist()
 
 
 
 
16
 
17
  my_credentials = {
18
  "type": "service_account",
 
42
  shuffled_pairs = state['shuffled_pairs']
43
  user_votes = state['user_votes']
44
  while pair_index < len(shuffled_pairs):
45
+ video_name, vista_id, gem_id = shuffled_pairs[pair_index]
46
+ pair_key = f"{vista_id}_{gem_id}"
47
  if pair_key not in user_votes:
48
  # Randomize left-right positions
49
  if random.choice([True, False]):
50
+ video1_id, video2_id = vista_id, gem_id
51
  else:
52
+ video1_id, video2_id = gem_id, vista_id
53
+ left_video_url = get_embed_link(video1_id)
54
+ right_video_url = get_embed_link(video2_id)
55
+ state['video_name'] = video_name
56
+ state['left_video_url'] = left_video_url
57
+ state['right_video_url'] = right_video_url
58
  state['video1_id'] = video1_id
59
  state['video2_id'] = video2_id
60
+ state['vista_id'] = vista_id
61
+ state['gem_id'] = gem_id
62
  return left_video_url, right_video_url
63
  else:
64
  pair_index += 1
 
66
  return None, None # No more pairs
67
 
68
  def generate_video_html(url):
69
+ return f'<iframe src="{url}" width="1024" height="576" allow="autoplay"></iframe>'
70
 
71
+ def save_vote(video_name, email, vista_id, gem_id, video1_id, video2_id, responses):
72
  vote_data = {
73
+ 'video_name': video_name,
74
  'email': email,
75
+ 'vista_id': vista_id,
76
+ 'gem_id': gem_id,
77
+ 'video1_id': video1_id,
78
+ 'video2_id': video2_id,
79
  'visual_quality': responses['visual_quality'],
80
  'temporal_consistency': responses['temporal_consistency'],
81
  'realistic_dynamics': responses['realistic_dynamics'],
 
88
  user_votes = set(user_doc.to_dict().get('votes', []))
89
  else:
90
  user_votes = set()
91
+ pair_key = f"{vista_id}_{gem_id}"
92
  user_votes.add(pair_key)
93
  user_ref.set({'votes': list(user_votes)}, merge=True)
94
 
 
96
  email = state['email']
97
  user_votes = state['user_votes']
98
  pair_index = state['pair_index']
 
 
99
  video1_id = state['video1_id']
100
  video2_id = state['video2_id']
101
+ vista_id = state['vista_id']
102
+ gem_id = state['gem_id']
103
+ video_name = state['video_name']
104
 
105
  # Save the user's responses
106
+ save_vote(video_name, email, vista_id, gem_id, video1_id, video2_id, responses)
107
 
108
  # Update state
109
  pair_index += 1
110
  state['pair_index'] = pair_index
111
 
112
  # Update user_votes in state
113
+ pair_key = f"{vista_id}_{gem_id}"
114
  user_votes.add(pair_key)
115
  state['user_votes'] = user_votes
116
 
 
119
  # No more pairs
120
  output_message = "Thank you for participating! No more videos."
121
  return (
122
+ gr.update(visible=False), # video_column
123
+ gr.update(visible=False), # video_column
124
  gr.update(value=""), # video1
125
  gr.update(value=""), # video2
126
  gr.update(visible=False), # question_column
 
137
  video2_html = generate_video_html(video2_url)
138
  # Update videos and reset questions
139
  return (
140
+ gr.update(visible=True), # video_column
141
+ gr.update(visible=True), # video_column
142
  gr.update(value=video1_html), # video1
143
  gr.update(value=video2_html), # video2
144
  gr.update(visible=True), # question_column
 
168
  gr.update(), # email_input (remains visible)
169
  gr.update(), # submit_email (remains visible)
170
  "Please enter a valid email.", # email_output
171
+ gr.update(visible=False), # video_column
172
+ gr.update(visible=False), # video_column
173
  gr.update(value=""), # video1
174
  gr.update(value=""), # video2
175
  gr.update(visible=False), # question_column
 
205
  gr.update(visible=False), # email_input
206
  gr.update(visible=False), # submit_email
207
  "", # email_output
208
+ gr.update(visible=False), # video_column
209
+ gr.update(visible=False), # video_column
210
  gr.update(value=""), # video1
211
  gr.update(value=""), # video2
212
  gr.update(visible=False), # question_column
 
221
  gr.update(visible=False), # email_input
222
  gr.update(visible=False), # submit_email
223
  "", # email_output
224
+ gr.update(visible=True), # video_column
225
+ gr.update(visible=True), # video_column
226
  gr.update(value=video1_html), # video1
227
  gr.update(value=video2_html), # video2
228
  gr.update(visible=True), # question_column
 
234
  with gr.Blocks() as demo:
235
  state = gr.State(value={})
236
 
237
+ gr.Markdown(
238
+ """
239
+ You'll be seeing pairs of videos and asked to compare them based on visual quality, temporal consistency, and realistic dynamics.
240
+ **Please try to reduce your “No Preference” choices as much as you can.**
241
+ """
242
+ )
243
+
244
  # Email Input
245
  email_input = gr.Textbox(label="Enter your email to begin:", placeholder="your.email@example.com", type="text")
246
  submit_email = gr.Button("Submit")
247
  email_output = gr.Markdown()
248
 
249
  # Video components (initially hidden)
250
+ with gr.Column(visible=False) as video1_column:
251
+ gr.Markdown("### Video 1")
252
+ video1 = gr.HTML()
253
+
254
+ with gr.Column(visible=False) as video2_column:
255
+ gr.Markdown("### Video 2")
256
+ video2 = gr.HTML()
257
 
258
  # Questions (initially hidden)
259
  with gr.Column(visible=False) as question_column:
260
  gr.Markdown("## Please answer the following questions:")
261
  q1 = gr.Radio(
262
+ choices=["Video 1", "Video 2", "No preference"],
263
  label="1. Which video has higher visual quality?",
264
  type="value"
265
  )
266
  q2 = gr.Radio(
267
+ choices=["Video 1", "Video 2", "No preference"],
268
+ label="2. Which video has more consistent motion over time?",
269
  type="value"
270
  )
271
  q3 = gr.Radio(
272
+ choices=["Video 1", "Video 2", "No preference"],
273
+ label="3. Which video has more more active agents?",
274
  type="value"
275
  )
276
 
 
293
  fn=on_next,
294
  inputs=[q1, q2, q3, state],
295
  outputs=[
296
+ video1_column, # Update video_column
297
+ video2_column, # Update video_column
298
  video1, # Update video1
299
  video2, # Update video2
300
  question_column, # Update question_column
 
332
  email_input, # Update email_input
333
  submit_email, # Update submit_email
334
  email_output, # Update email_output
335
+ video1_column, # Update video_column
336
+ video2_column, # Update video_column
337
  video1, # Update video1
338
  video2, # Update video2
339
  question_column, # Update question_column
file_pairs.csv ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ file_name,vista_id,gem_id
2
+ OpenDV_000127.mp4,1cmpYkCq97BEFum4Qn1YVQFSQJjGPjn7h,1WNeoL3Ah7FfObRMirJhl8ulXJ9mgTUWD
3
+ OpenDV_000173.mp4,15RAIFmQn_WuTWBDA4YxdvpTEBJeQFKy1,1zNLz0f3O6ujJ_flCUjEoUA0kGtzbEfN7
4
+ OpenDV_000220.mp4,13GMWYQtqC6JukyShAa8PIKM5PnKigTPi,1KMhFZZYibz5qWcolq2gkmTimLV9JQJX3
5
+ OpenDV_000628.mp4,1l9gRscF7VKbfb3ifGJqWr_rVqeD4DKED,1phLaOuOy7V_cxCoBEfuhlRnFKM11aWXs
6
+ OpenDV_000644.mp4,1ko_OkjFIEMNKXAFZKwxVv43ALyf6qWZ1,1cEtrPjuZxvDY1Z45hONftLctlh2eAgU_
7
+ OpenDV_000748.mp4,1Ecl-TT5YQlVAvHKphTWYum4sNjiqzIK0,1rsWsWeyDSKAfRaXbQde6wWjw6mtVZzMw
8
+ OpenDV_000782.mp4,1nlQZtGWyFfHFsIhkX5FgFpDIn6jI2Iu7,12TWQz_pUKLu9CVCMXFd2apHqn6uaPdnZ
9
+ OpenDV_000868.mp4,1YsWgy-v7BxBEYD-8psJ6oz7ms0jYySX0,1Em_RKfUixYQlZPjddCnAsN7hjiML2qff
10
+ OpenDV_001015.mp4,1P8GTCH4xFT_fQE2GcmObURxsPTDxXiOY,1UL0NuJhfUjDQgLvksDnTj0lPHq-4-U2M
11
+ OpenDV_001151.mp4,10Rifh1a5djstRSZ4enfepM2iIR_wCyal,1d2Vi4R6DqE9QIUa1spV6qF-fICUtsspW
12
+ OpenDV_001268.mp4,1Ym4qHhbzUElsx1dC_MJEciGkY5pE3EOG,1SaXHb_PjMJ94sfMRL96Zco00iPeePV8j
13
+ OpenDV_001369.mp4,1Qduap5JCByjWOQYc0o-1zWQl5i7bxpPR,1QQJ_7TYYRbFXWzTKUvUr5EwhnNwOCRaE
14
+ OpenDV_001482.mp4,1Wfw8p1q4Kuadf1Go_E7Lgd7g9zCtMLtG,1m1albGu1niEqU5vNdOA8-PbUd6Ye6AAq
15
+ OpenDV_001661.mp4,1lFJ8A8DJ3lXzyfExPJDDypUISNK7kfL3,1s245_q9a1BKHn2PglR1S-1uSVkc-0UON
16
+ OpenDV_001907.mp4,1y9QsHa6Xx0kycS83niLOkZ_SaB6kuF6O,1LQ0OePWt754bovzjXnvw0xDdkYe8M_h_
17
+ OpenDV_002142.mp4,1ZfL4otUU5r0aJjOHUsTtq533Xh-OzGNZ,1qy63BohNaqlKJJn9aebQcy_oQ-5aPB2Y
18
+ OpenDV_002847.mp4,12RmGXlmRHH8LGOB2ZegEb_HZYR0HftE8,1bxbyFn9SNpH3hCocn_MnmtMvmx_CK5G7
19
+ OpenDV_003243.mp4,1cY5bLgMCNEyDgFxXC_1K-4k5hpKeUODl,1apjWkRca84dwN8GitmKeOeV4_V5OXx9z
20
+ OpenDV_003414.mp4,1ni78Zg2D4VUZb0Yop3mX82sF-N5P1mzv,1MS4W9uBf0We8Gp661ww-0MNM5qDsQoYp
21
+ OpenDV_003521.mp4,1ZP4yDEOG8pO6PVZMqfu7RlRMkS0G1zhZ,1IIELh95WWmFrBKantz5fsOj6xrw2mrqw
22
+ OpenDV_003681.mp4,15ds8XbjLJTIPnFVykuA_Q9TWjhVKroTr,1s4LFc0yLc2y7a9L_47_-X65-vsw5AuIr
23
+ OpenDV_003792.mp4,1k9lU0Eo-N5lck7QQE3szZoeE0mVFIHbp,1O8-PTvNXBKLAD8oFt0-IzCEIVpXQsOV1
24
+ OpenDV_003959.mp4,1GanR1Jxj82rJdduzbIRX39gSQuEKOcuS,1iPZ24gqRzGJTDbm0HMCxjOyjhrE173Eo
25
+ OpenDV_004275.mp4,1tvg3WClYikOA6gg_M1ZgvnNm7dhv5mDj,1T9FeF1lavHNS4VrZNdk9pKC7ozOVrOlj
26
+ OpenDV_004393.mp4,11wPRnaJdrnH6VrNnuYcnWaGoY3W14S2q,1rYNUWryo6gWkayMk8UVTXyHDwWIaJoF1
27
+ OpenDV_004418.mp4,1Ef7JAnzPLBkX1jNr33y-tkuB8S-yn92k,1kCrtsz4ge5qBlFSOXmmZmJmjtxnR3Imd
28
+ OpenDV_004570.mp4,1X7VmayarfKSIPX-BKoaU__vhkUqJ9UDD,15riJQ6wfdLETGuzuFQEC5swSVYL2kqwK
29
+ OpenDV_004623.mp4,158m0_Ye64jEUhjlPDYiQpeRhTeKoEgtw,14p2d1ZfVRUp9vYZO_qup3zYBEFvWR7pw
30
+ OpenDV_004717.mp4,1sYAKla_ZsOe9WBvZn8dumCY6esL8P2qI,1VlvEiJTkYg9Ro5F0q6iWfQ75snGUUDsZ
31
+ OpenDV_004881.mp4,1sZGcbHMgUB3CE1-kQuS0qx_oRLVTqeYy,1MyaGNcStDIZB40zWodeVstrtbnZzYZRe
get_drive.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ VISTA_FOLDER_ID = "10xTrOHOFku5C-MnatdiYuqzBKJXzt4kJ"
2
+ GEM_FOLDER_ID = "1-rmwZlTklf5w8oNr75Xeb6M1L7RvlS6C"
3
+
4
+ from pydrive.auth import GoogleAuth
5
+ import pandas as pd
6
+ from pydrive.drive import GoogleDrive
7
+ # Rename the downloaded JSON file to client_secrets.json
8
+ # The client_secrets.json file needs to be in the same directory as the script.
9
+ gauth = GoogleAuth()
10
+ drive = GoogleDrive(gauth)
11
+ # List files in Google Drive
12
+ fileList = drive.ListFile({'q': f"'{VISTA_FOLDER_ID}' in parents and trashed=false"}).GetList()
13
+ vista_files = [(file1['title'], file1['id']) for file1 in fileList]
14
+
15
+ fileList = drive.ListFile({'q': f"'{GEM_FOLDER_ID}' in parents and trashed=false"}).GetList()
16
+ gem_files = [(file1['title'], file1['id']) for file1 in fileList]
17
+
18
+ # Match files by title and create a csv
19
+ data = []
20
+
21
+ for vista_file in vista_files:
22
+ for gem_file in gem_files:
23
+ if vista_file[0] == gem_file[0]:
24
+ data.append((vista_file[0], vista_file[1], gem_file[1]))
25
+
26
+ # sort by file_name
27
+ data.sort(key=lambda x: x[0])
28
+ df = pd.DataFrame(data, columns=['file_name', 'vista_id', 'gem_id'])
29
+ df.to_csv('file_pairs.csv', index=False)
get_results.py ADDED
File without changes
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  gradio
2
  firebase-admin
3
- python-dotenv
 
 
1
  gradio
2
  firebase-admin
3
+ python-dotenv
4
+ pandas