Spaces:
Sleeping
Sleeping
Commit
·
a4bc7df
1
Parent(s):
7e1033f
Update app.py
Browse files
app.py
CHANGED
@@ -55,7 +55,27 @@ def get_huggingface_dataset():
|
|
55 |
log_file = os.path.join(dataset_dir, "flag_data.csv")
|
56 |
return repo, log_file
|
57 |
|
58 |
-
def update(user_choice, data_folder=VIDEO_PATH):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
envs = parse_envs()
|
60 |
env_name = envs[random.randint(0, len(envs)-1)]
|
61 |
# choose video
|
@@ -64,23 +84,12 @@ def update(user_choice, data_folder=VIDEO_PATH):
|
|
64 |
for f in videos:
|
65 |
if f.endswith(f'.{FORMAT}'):
|
66 |
video_files.append(os.path.join(data_folder, env_name, f))
|
67 |
-
# choose two videos
|
68 |
selected_video_ids = np.random.choice(len(video_files), 2, replace=False)
|
69 |
left = video_files[selected_video_ids[0]]
|
70 |
right = video_files[selected_video_ids[1]]
|
71 |
-
|
72 |
-
|
73 |
-
current_time = strftime("%Y-%m-%d-%H-%M-%S", gmtime())
|
74 |
-
info = [env_name, user_choice, left, right, current_time]
|
75 |
-
print(info)
|
76 |
-
|
77 |
-
repo, log_file = get_huggingface_dataset() # flag without using gradio flagging
|
78 |
-
with open(log_file, 'a') as file: # incremental change of the file
|
79 |
-
writer_object = writer(file)
|
80 |
-
writer_object.writerow(info)
|
81 |
-
file.close()
|
82 |
-
repo.push_to_hub(commit_message=f"Flagged sample at {current_time}")
|
83 |
-
|
84 |
return left, right
|
85 |
|
86 |
def replay(left, right):
|
@@ -107,23 +116,26 @@ def build_interface(iter=3, data_folder=VIDEO_PATH):
|
|
107 |
gr.Markdown("Here is RoboTinder!")
|
108 |
gr.Markdown("Select the best robot behaviour in your choice!")
|
109 |
with gr.Row():
|
110 |
-
# some initial
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
if FORMAT == 'mp4':
|
112 |
-
left_video_path = os.path.join(os.path.dirname(__file__),
|
113 |
-
f"{VIDEO_PATH}/rl-video-episode-0.mp4")
|
114 |
-
right_video_path = os.path.join(os.path.dirname(__file__),
|
115 |
-
f"{VIDEO_PATH}/rl-video-episode-1.mp4")
|
116 |
left = gr.PlayableVideo(left_video_path, label="left_video")
|
117 |
right = gr.PlayableVideo(right_video_path, label="right_video")
|
118 |
else:
|
119 |
-
left_video_path = os.path.join(os.path.dirname(__file__),
|
120 |
-
f"{VIDEO_PATH}/rl-video-episode-0.gif")
|
121 |
-
right_video_path = os.path.join(os.path.dirname(__file__),
|
122 |
-
f"{VIDEO_PATH}/rl-video-episode-1.gif")
|
123 |
left = gr.Image(left_video_path, shape=(1024, 768), label="left_video")
|
124 |
# right = gr.Image(right_video_path).style(height=768, width=1024)
|
125 |
right = gr.Image(right_video_path, label="right_video")
|
126 |
|
|
|
|
|
|
|
|
|
|
|
127 |
btn1 = gr.Button("Replay")
|
128 |
user_choice = gr.Radio(["Left", "Right", "Not Sure"], label="Which one is your favorite?")
|
129 |
btn2 = gr.Button("Next")
|
@@ -140,6 +152,9 @@ def build_interface(iter=3, data_folder=VIDEO_PATH):
|
|
140 |
return demo
|
141 |
|
142 |
if __name__ == "__main__":
|
|
|
|
|
|
|
143 |
demo = build_interface()
|
144 |
# demo.launch(share=True)
|
145 |
demo.launch(share=False)
|
|
|
55 |
log_file = os.path.join(dataset_dir, "flag_data.csv")
|
56 |
return repo, log_file
|
57 |
|
58 |
+
def update(user_choice, left, right, data_folder=VIDEO_PATH, flag_to_huggingface=True):
|
59 |
+
global last_left_video_path
|
60 |
+
global last_right_video_path
|
61 |
+
|
62 |
+
if flag_to_huggingface: # log
|
63 |
+
env_name = str(last_left_video_path).split('/')[1] # 'robotinder-data/ENV_NAME/'
|
64 |
+
current_time = strftime("%Y-%m-%d-%H-%M-%S", gmtime())
|
65 |
+
info = [env_name, user_choice, last_left_video_path, last_right_video_path, current_time]
|
66 |
+
print(info)
|
67 |
+
repo, log_file = get_huggingface_dataset()
|
68 |
+
with open(log_file, 'a') as file: # incremental change of the file
|
69 |
+
writer_object = writer(file)
|
70 |
+
writer_object.writerow(info)
|
71 |
+
file.close()
|
72 |
+
if int(current_time.split('-')[-2]) % 2 == 0:
|
73 |
+
try:
|
74 |
+
repo.push_to_hub(commit_message=f"Flagged sample at {current_time}")
|
75 |
+
except:
|
76 |
+
repo.git_pull(lfs=True) # sync with remote first
|
77 |
+
repo.push_to_hub(commit_message=f"Flagged sample at {current_time}")
|
78 |
+
|
79 |
envs = parse_envs()
|
80 |
env_name = envs[random.randint(0, len(envs)-1)]
|
81 |
# choose video
|
|
|
84 |
for f in videos:
|
85 |
if f.endswith(f'.{FORMAT}'):
|
86 |
video_files.append(os.path.join(data_folder, env_name, f))
|
87 |
+
# randomly choose two videos
|
88 |
selected_video_ids = np.random.choice(len(video_files), 2, replace=False)
|
89 |
left = video_files[selected_video_ids[0]]
|
90 |
right = video_files[selected_video_ids[1]]
|
91 |
+
last_left_video_path = left
|
92 |
+
last_right_video_path = right
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
return left, right
|
94 |
|
95 |
def replay(left, right):
|
|
|
116 |
gr.Markdown("Here is RoboTinder!")
|
117 |
gr.Markdown("Select the best robot behaviour in your choice!")
|
118 |
with gr.Row():
|
119 |
+
# some initial values
|
120 |
+
envs = parse_envs()
|
121 |
+
env_name = envs[random.randint(0, len(envs)-1)] # random pick an env
|
122 |
+
left_video_path = os.path.join(os.path.dirname(__file__),
|
123 |
+
f"{VIDEO_PATH}/{env_name}/rl-video-episode-0.{FORMAT}")
|
124 |
+
right_video_path = os.path.join(os.path.dirname(__file__),
|
125 |
+
f"{VIDEO_PATH}/{env_name}/rl-video-episode-1.{FORMAT}")
|
126 |
if FORMAT == 'mp4':
|
|
|
|
|
|
|
|
|
127 |
left = gr.PlayableVideo(left_video_path, label="left_video")
|
128 |
right = gr.PlayableVideo(right_video_path, label="right_video")
|
129 |
else:
|
|
|
|
|
|
|
|
|
130 |
left = gr.Image(left_video_path, shape=(1024, 768), label="left_video")
|
131 |
# right = gr.Image(right_video_path).style(height=768, width=1024)
|
132 |
right = gr.Image(right_video_path, label="right_video")
|
133 |
|
134 |
+
global last_left_video_path
|
135 |
+
last_left_video_path = left_video_path
|
136 |
+
global last_right_video_path
|
137 |
+
last_right_video_path = right_video_path
|
138 |
+
|
139 |
btn1 = gr.Button("Replay")
|
140 |
user_choice = gr.Radio(["Left", "Right", "Not Sure"], label="Which one is your favorite?")
|
141 |
btn2 = gr.Button("Next")
|
|
|
152 |
return demo
|
153 |
|
154 |
if __name__ == "__main__":
|
155 |
+
last_left_video_path = None
|
156 |
+
last_right_video_path = None
|
157 |
+
|
158 |
demo = build_interface()
|
159 |
# demo.launch(share=True)
|
160 |
demo.launch(share=False)
|