czyang commited on
Commit
5120ed0
·
verified ·
1 Parent(s): 1096c2e
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +21 -0
  2. app.py +175 -0
  3. videos/foleycrafter/01-cello-chainsaw.mp4 +0 -0
  4. videos/foleycrafter/01-cello-erhu.mp4 +0 -0
  5. videos/foleycrafter/01-cello.mp4 +0 -0
  6. videos/foleycrafter/02-bird-male.mp4 +0 -0
  7. videos/foleycrafter/02-bird-rooster.mp4 +0 -0
  8. videos/foleycrafter/02-bird.mp4 +0 -0
  9. videos/foleycrafter/03-dog-car.mp4 +0 -0
  10. videos/foleycrafter/03-dog-drum.mp4 +0 -0
  11. videos/foleycrafter/03-dog.mp4 +0 -0
  12. videos/foleycrafter/04-typewriter-keyboard.mp4 +3 -0
  13. videos/foleycrafter/04-typewriter-piano.mp4 +3 -0
  14. videos/foleycrafter/04-typewriter.mp4 +3 -0
  15. videos/foleycrafter/05-gun-bird.mp4 +0 -0
  16. videos/foleycrafter/05-gun-drum.mp4 +0 -0
  17. videos/foleycrafter/05-gun.mp4 +0 -0
  18. videos/foleycrafter/06-chop-dog.mp4 +0 -0
  19. videos/foleycrafter/06-chop-drum.mp4 +0 -0
  20. videos/foleycrafter/06-chop.mp4 +0 -0
  21. videos/foleycrafter/07-lion-cat.mp4 +3 -0
  22. videos/foleycrafter/07-lion-elephant.mp4 +3 -0
  23. videos/foleycrafter/07-lion.mp4 +0 -0
  24. videos/foleycrafter/08-squeeze-bone.mp4 +3 -0
  25. videos/foleycrafter/08-squeeze-scream.mp4 +3 -0
  26. videos/foleycrafter/08-squeeze.mp4 +3 -0
  27. videos/foleycrafter/09-trumpet-flute.mp4 +0 -0
  28. videos/foleycrafter/09-trumpet-saxophone.mp4 +0 -0
  29. videos/foleycrafter/09-trumpet.mp4 +0 -0
  30. videos/foleycrafter/10-golf-explosion.mp4 +3 -0
  31. videos/foleycrafter/10-golf-scream.mp4 +3 -0
  32. videos/foleycrafter/10-golf.mp4 +3 -0
  33. videos/ours/.DS_Store +0 -0
  34. videos/ours/01-cello-chainsaw.mp4 +0 -0
  35. videos/ours/01-cello-erhu.mp4 +0 -0
  36. videos/ours/01-cello.mp4 +0 -0
  37. videos/ours/02-bird-male.mp4 +0 -0
  38. videos/ours/02-bird-rooster.mp4 +0 -0
  39. videos/ours/02-bird.mp4 +0 -0
  40. videos/ours/03-dog-car.mp4 +0 -0
  41. videos/ours/03-dog-drum.mp4 +0 -0
  42. videos/ours/03-dog.mp4 +0 -0
  43. videos/ours/04-typewriter-keyboard.mp4 +3 -0
  44. videos/ours/04-typewriter-piano.mp4 +3 -0
  45. videos/ours/04-typewriter.mp4 +3 -0
  46. videos/ours/05-gun-bird.mp4 +0 -0
  47. videos/ours/05-gun-drum.mp4 +0 -0
  48. videos/ours/05-gun.mp4 +0 -0
  49. videos/ours/06-chop-dog.mp4 +0 -0
  50. videos/ours/06-chop-drum.mp4 +0 -0
.gitattributes CHANGED
@@ -33,3 +33,24 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ videos/foleycrafter/04-typewriter-keyboard.mp4 filter=lfs diff=lfs merge=lfs -text
37
+ videos/foleycrafter/04-typewriter-piano.mp4 filter=lfs diff=lfs merge=lfs -text
38
+ videos/foleycrafter/04-typewriter.mp4 filter=lfs diff=lfs merge=lfs -text
39
+ videos/foleycrafter/07-lion-cat.mp4 filter=lfs diff=lfs merge=lfs -text
40
+ videos/foleycrafter/07-lion-elephant.mp4 filter=lfs diff=lfs merge=lfs -text
41
+ videos/foleycrafter/08-squeeze-bone.mp4 filter=lfs diff=lfs merge=lfs -text
42
+ videos/foleycrafter/08-squeeze-scream.mp4 filter=lfs diff=lfs merge=lfs -text
43
+ videos/foleycrafter/08-squeeze.mp4 filter=lfs diff=lfs merge=lfs -text
44
+ videos/foleycrafter/10-golf-explosion.mp4 filter=lfs diff=lfs merge=lfs -text
45
+ videos/foleycrafter/10-golf-scream.mp4 filter=lfs diff=lfs merge=lfs -text
46
+ videos/foleycrafter/10-golf.mp4 filter=lfs diff=lfs merge=lfs -text
47
+ videos/ours/04-typewriter-keyboard.mp4 filter=lfs diff=lfs merge=lfs -text
48
+ videos/ours/04-typewriter-piano.mp4 filter=lfs diff=lfs merge=lfs -text
49
+ videos/ours/04-typewriter.mp4 filter=lfs diff=lfs merge=lfs -text
50
+ videos/ours/07-lion-cat.mp4 filter=lfs diff=lfs merge=lfs -text
51
+ videos/ours/07-lion-elephant.mp4 filter=lfs diff=lfs merge=lfs -text
52
+ videos/ours/08-squeeze-bone.mp4 filter=lfs diff=lfs merge=lfs -text
53
+ videos/ours/08-squeeze-scream.mp4 filter=lfs diff=lfs merge=lfs -text
54
+ videos/ours/10-golf-explosion.mp4 filter=lfs diff=lfs merge=lfs -text
55
+ videos/ours/10-golf-scream.mp4 filter=lfs diff=lfs merge=lfs -text
56
+ videos/ours/10-golf.mp4 filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ from datetime import datetime
4
+ import random
5
+ import os
6
+ from huggingface_hub import Repository
7
+ random.seed(1234)
8
+
9
+ import subprocess
10
+ # Set Git user information
11
+ subprocess.run(["git", "config", "--global", "user.email", "[email protected]"])
12
+ subprocess.run(["git", "config", "--global", "user.name", "czyang"])
13
+
14
+
15
+ hf_token = os.getenv("HF_TOKEN")
16
+ print("HF Token is none?", hf_token is None)
17
+
18
+ # Initialize the repository
19
+ DATASET_REPO_URL = "https://huggingface.co/datasets/czyang/Foley-User-Study-Response-V2"
20
+ repo = Repository(
21
+ local_dir="user_responses",
22
+ clone_from=DATASET_REPO_URL,
23
+ use_auth_token=hf_token
24
+ )
25
+
26
+ def prepare_test_cases():
27
+ json_path = "videos/videos.json"
28
+ with open(json_path, "r") as f:
29
+ video_dict = json.load(f)
30
+
31
+ video_ids = list(video_dict.keys())
32
+ for video_id in video_ids:
33
+ if random.random() > 0.5:
34
+ video_list = [video_dict[video_id]['ours'], video_dict[video_id]['foleycrafter']]
35
+ else:
36
+ video_list = [video_dict[video_id]['foleycrafter'], video_dict[video_id]['ours']]
37
+
38
+ random.shuffle(video_list)
39
+
40
+ video_dict[video_id]['Video 1'] = video_list[0]
41
+ video_dict[video_id]['Video 2'] = video_list[1]
42
+
43
+ return video_dict
44
+
45
+ video_dict = prepare_test_cases()
46
+ video_ids = list(video_dict.keys())
47
+ random.shuffle(video_ids)
48
+
49
+
50
+ questions = [
51
+ "Which video's audio best matches the sound of {}?",
52
+ "In which video is the timing of the audio best synchronized with what you can see in the video?",
53
+ "Assuming the video is meant to sound like {}, which video has the best audio overall?"
54
+ ]
55
+ submissions_file = "user_responses/response.jsonl"
56
+
57
+ def has_already_submitted(user_id):
58
+ if os.path.exists(submissions_file):
59
+ with open(submissions_file, "r") as f:
60
+ for line in f:
61
+ submission = json.loads(line)
62
+ if submission.get("u_id") == user_id:
63
+ return True
64
+ return False
65
+
66
+ # Save responses
67
+ def save_responses(unique_submission, *responses):
68
+ timestamp = datetime.now().isoformat()
69
+ info = responses[-1]
70
+ responses = responses[:-1]
71
+ unique_id = info["session_id"]
72
+ user_id = f"{unique_id}"
73
+
74
+ # Check for unique submission
75
+ if unique_submission and has_already_submitted(user_id):
76
+ return "You have already submitted responses. Thank you for participating!"
77
+
78
+ # Initialize the result dictionary
79
+ result = {
80
+ "u_id": user_id,
81
+ "timestamp": timestamp,
82
+ "responses": []
83
+ }
84
+
85
+ for index in range(len(video_ids)):
86
+ start_idx = index * len(questions)
87
+ end_idx = start_idx + len(questions)
88
+
89
+ response = responses[start_idx:end_idx]
90
+ if any(r is None for r in response):
91
+ return "Please answer all questions before submitting."
92
+
93
+ video_id = video_ids[index]
94
+ pair_response = {
95
+ video_id: {
96
+ 'semantic': video_dict[video_id][response[0]],
97
+ 'sync': video_dict[video_id][response[1]],
98
+ 'overall': video_dict[video_id][response[2]],
99
+ }
100
+ }
101
+ result["responses"].append(pair_response)
102
+
103
+ result["responses"] = sorted(result["responses"], key=lambda x: x.keys())
104
+
105
+ # Save response locally and push to Hugging Face Hub
106
+ with open(submissions_file, "a") as f:
107
+ f.write(json.dumps(result) + "\n")
108
+
109
+ # Push changes to the Hugging Face dataset repo
110
+ repo.push_to_hub()
111
+
112
+ return "All responses saved! Thank you for participating!"
113
+
114
+
115
+
116
+
117
+ def create_interface(unique_submission=False):
118
+ with gr.Blocks() as demo:
119
+ gr.Markdown("# Human Preference Study: Video Comparison")
120
+ gr.Markdown("""
121
+ In this study, you will watch (and listen to) pairs of videos side by side.
122
+
123
+ Please watch and **listen** to each pair of videos carefully and answer the three associated questions.
124
+
125
+ **Headphones are recommended!**
126
+ """)
127
+
128
+ # Display video pairs and questions
129
+ responses = []
130
+ for index, video_id in enumerate(video_ids):
131
+ video1 = video_dict[video_id]['Video 1']
132
+ video2 = video_dict[video_id]['Video 2']
133
+ audio_prompt = video_dict[video_id]['audio prompt']
134
+
135
+ gr.Markdown(f"### Video Pair {index + 1}")
136
+ with gr.Row():
137
+ gr.Video(video1, label="Video 1")
138
+ gr.Video(video2, label="Video 2")
139
+ with gr.Column():
140
+ responses.append(gr.Radio(["Video 1", "Video 2"], label=questions[0].format(audio_prompt), value=None))
141
+ responses.append(gr.Radio(["Video 1", "Video 2"], label=questions[1], value=None))
142
+ responses.append(gr.Radio(["Video 1", "Video 2"], label=questions[2].format(audio_prompt), value=None))
143
+
144
+ gr.Markdown("---")
145
+
146
+ info = gr.JSON(visible=False)
147
+ demo.load(predict, None, info)
148
+
149
+ submit_btn = gr.Button("Submit")
150
+ result_message = gr.Textbox(label="Message (please only submit once)", interactive=False)
151
+
152
+ submit_btn.click(
153
+ fn=lambda *args: save_responses(unique_submission, *args),
154
+ inputs=responses+[info],
155
+ outputs=result_message
156
+ )
157
+
158
+ return demo
159
+
160
+ def predict(request: gr.Request):
161
+ headers = request.headers
162
+ host = request.client.host
163
+ user_agent = request.headers["user-agent"]
164
+ session_id = request.session_hash
165
+ return {
166
+ "ip": host,
167
+ "user_agent": user_agent,
168
+ "headers": headers,
169
+ "session_id": session_id
170
+ }
171
+
172
+ if __name__ == "__main__":
173
+ # Launch with unique_submission set based on `--unique` flag
174
+ demo = create_interface(unique_submission=True)
175
+ demo.launch(share=True)
videos/foleycrafter/01-cello-chainsaw.mp4 ADDED
Binary file (414 kB). View file
 
videos/foleycrafter/01-cello-erhu.mp4 ADDED
Binary file (414 kB). View file
 
videos/foleycrafter/01-cello.mp4 ADDED
Binary file (407 kB). View file
 
videos/foleycrafter/02-bird-male.mp4 ADDED
Binary file (345 kB). View file
 
videos/foleycrafter/02-bird-rooster.mp4 ADDED
Binary file (345 kB). View file
 
videos/foleycrafter/02-bird.mp4 ADDED
Binary file (334 kB). View file
 
videos/foleycrafter/03-dog-car.mp4 ADDED
Binary file (443 kB). View file
 
videos/foleycrafter/03-dog-drum.mp4 ADDED
Binary file (443 kB). View file
 
videos/foleycrafter/03-dog.mp4 ADDED
Binary file (407 kB). View file
 
videos/foleycrafter/04-typewriter-keyboard.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:73148b48b5344edafc7d303b67ae60d0c37cd8c22ded0ec6b2c1068b340ca933
3
+ size 1140333
videos/foleycrafter/04-typewriter-piano.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:31ad57b9dfa33055f27db3d2c65cfe6227c4cb5214ea5b96e0bd3d40b136e6ad
3
+ size 1140333
videos/foleycrafter/04-typewriter.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9dfd68a98bc39e32f72f1cef3d3824e6a9e0af5f02010c73448188f47244d17f
3
+ size 1123257
videos/foleycrafter/05-gun-bird.mp4 ADDED
Binary file (766 kB). View file
 
videos/foleycrafter/05-gun-drum.mp4 ADDED
Binary file (766 kB). View file
 
videos/foleycrafter/05-gun.mp4 ADDED
Binary file (746 kB). View file
 
videos/foleycrafter/06-chop-dog.mp4 ADDED
Binary file (509 kB). View file
 
videos/foleycrafter/06-chop-drum.mp4 ADDED
Binary file (509 kB). View file
 
videos/foleycrafter/06-chop.mp4 ADDED
Binary file (488 kB). View file
 
videos/foleycrafter/07-lion-cat.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:70d56dbc76ad0a1d2de64675a1d7768b8776d3f354adc39558ab4368c144a20c
3
+ size 1081399
videos/foleycrafter/07-lion-elephant.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:58ef42ac6a63bdde04ef2e6f394d26e7e7ec0e30c48e14afbaa64b3c72583067
3
+ size 1081399
videos/foleycrafter/07-lion.mp4 ADDED
Binary file (983 kB). View file
 
videos/foleycrafter/08-squeeze-bone.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0d07fb408a95a281ccbedad309fa56380162ebb591d38f659356a34e9add5afa
3
+ size 1106678
videos/foleycrafter/08-squeeze-scream.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c203955ea99c2ffd3330bcd71bf714097743bf0db36801aa38673fa8514ab4f
3
+ size 1106678
videos/foleycrafter/08-squeeze.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b705822176ec978c3b7eaf48b8e9dcf41802545158ccd0cd16de1320d67ae242
3
+ size 1044540
videos/foleycrafter/09-trumpet-flute.mp4 ADDED
Binary file (579 kB). View file
 
videos/foleycrafter/09-trumpet-saxophone.mp4 ADDED
Binary file (579 kB). View file
 
videos/foleycrafter/09-trumpet.mp4 ADDED
Binary file (569 kB). View file
 
videos/foleycrafter/10-golf-explosion.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:228141950e3da917815b70b1feede266f29303f4137b4b8986877fc5345530db
3
+ size 2707753
videos/foleycrafter/10-golf-scream.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4316ceb0fee0390a13277fafeb3f02b2bd0ffcbe5cf437b6dc000faabd77e19f
3
+ size 2707753
videos/foleycrafter/10-golf.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:60136d9a2d9b24cf6546c09867b30c3dd82d329edfdeb3793afc77532ac1efaa
3
+ size 2583278
videos/ours/.DS_Store ADDED
Binary file (8.2 kB). View file
 
videos/ours/01-cello-chainsaw.mp4 ADDED
Binary file (340 kB). View file
 
videos/ours/01-cello-erhu.mp4 ADDED
Binary file (340 kB). View file
 
videos/ours/01-cello.mp4 ADDED
Binary file (332 kB). View file
 
videos/ours/02-bird-male.mp4 ADDED
Binary file (273 kB). View file
 
videos/ours/02-bird-rooster.mp4 ADDED
Binary file (273 kB). View file
 
videos/ours/02-bird.mp4 ADDED
Binary file (252 kB). View file
 
videos/ours/03-dog-car.mp4 ADDED
Binary file (388 kB). View file
 
videos/ours/03-dog-drum.mp4 ADDED
Binary file (388 kB). View file
 
videos/ours/03-dog.mp4 ADDED
Binary file (361 kB). View file
 
videos/ours/04-typewriter-keyboard.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7eeef131f1fcdbf5dde11169f86e67f8be8722037fe05048e88099ba34d65d8f
3
+ size 1082586
videos/ours/04-typewriter-piano.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bbab300707e375fe0347465ba445b785cfa6e7783d17ed60a2fe7ad43664f18f
3
+ size 1082454
videos/ours/04-typewriter.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:916a1d8cbbe426a952849ca9babeb8fb29934ec9b754122679b08b60ba1e0e92
3
+ size 1063941
videos/ours/05-gun-bird.mp4 ADDED
Binary file (735 kB). View file
 
videos/ours/05-gun-drum.mp4 ADDED
Binary file (737 kB). View file
 
videos/ours/05-gun.mp4 ADDED
Binary file (707 kB). View file
 
videos/ours/06-chop-dog.mp4 ADDED
Binary file (417 kB). View file
 
videos/ours/06-chop-drum.mp4 ADDED
Binary file (456 kB). View file