Spaces:
Sleeping
Sleeping
Commit
·
4259255
1
Parent(s):
af9aa0c
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,18 +24,37 @@ def video_identity(video):
|
|
| 24 |
def nan():
|
| 25 |
return None
|
| 26 |
|
| 27 |
-
# demo = gr.Interface(video_identity,
|
| 28 |
-
# gr.Video(),
|
| 29 |
-
# "playable_video",
|
| 30 |
-
# examples=[
|
| 31 |
-
# os.path.join(os.path.dirname(__file__),
|
| 32 |
-
# "videos/rl-video-episode-0.mp4")],
|
| 33 |
-
# cache_examples=True)
|
| 34 |
-
|
| 35 |
FORMAT = ['mp4', 'gif'][1]
|
| 36 |
|
| 37 |
-
def
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
envs = parse_envs()
|
| 40 |
env_name = envs[random.randint(0, len(envs)-1)]
|
| 41 |
# choose video
|
|
@@ -53,25 +72,15 @@ def update(user_choice, data_folder='videos'):
|
|
| 53 |
current_time = strftime("%Y-%m-%d-%H-%M-%S", gmtime())
|
| 54 |
info = [env_name, user_choice, left, right, current_time]
|
| 55 |
print(info)
|
| 56 |
-
|
|
|
|
|
|
|
| 57 |
writer_object = writer(file)
|
| 58 |
writer_object.writerow(info)
|
| 59 |
file.close()
|
| 60 |
-
|
| 61 |
|
| 62 |
-
|
| 63 |
-
# if FORMAT == 'mp4':
|
| 64 |
-
# left = os.path.join(os.path.dirname(__file__),
|
| 65 |
-
# "videos/rl-video-episode-2.mp4")
|
| 66 |
-
# right = os.path.join(os.path.dirname(__file__),
|
| 67 |
-
# "videos/rl-video-episode-3.mp4")
|
| 68 |
-
# else:
|
| 69 |
-
# left = os.path.join(os.path.dirname(__file__),
|
| 70 |
-
# "videos/rl-video-episode-2.gif")
|
| 71 |
-
# right = os.path.join(os.path.dirname(__file__),
|
| 72 |
-
# "videos/rl-video-episode-3.gif")
|
| 73 |
-
# print(left, right)
|
| 74 |
-
# return left, right
|
| 75 |
|
| 76 |
def replay(left, right):
|
| 77 |
return left, right
|
|
|
|
| 24 |
def nan():
|
| 25 |
return None
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
FORMAT = ['mp4', 'gif'][1]
|
| 28 |
|
| 29 |
+
def get_huggingface_dataset():
|
| 30 |
+
try:
|
| 31 |
+
import huggingface_hub
|
| 32 |
+
except (ImportError, ModuleNotFoundError):
|
| 33 |
+
raise ImportError(
|
| 34 |
+
"Package `huggingface_hub` not found is needed "
|
| 35 |
+
"for HuggingFaceDatasetSaver. Try 'pip install huggingface_hub'."
|
| 36 |
+
)
|
| 37 |
+
HF_TOKEN = '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' # my HF token
|
| 38 |
+
DATASET_NAME = 'crowdsourced-robotinder-demo'
|
| 39 |
+
FLAGGING_DIR = 'flag/'
|
| 40 |
+
path_to_dataset_repo = huggingface_hub.create_repo(
|
| 41 |
+
repo_id=DATASET_NAME,
|
| 42 |
+
token=HF_TOKEN,
|
| 43 |
+
private=False,
|
| 44 |
+
repo_type="dataset",
|
| 45 |
+
exist_ok=True,
|
| 46 |
+
)
|
| 47 |
+
dataset_dir = os.path.join(DATASET_NAME, FLAGGING_DIR)
|
| 48 |
+
repo = huggingface_hub.Repository(
|
| 49 |
+
local_dir=dataset_dir,
|
| 50 |
+
clone_from=path_to_dataset_repo,
|
| 51 |
+
use_auth_token=HF_TOKEN,
|
| 52 |
+
)
|
| 53 |
+
repo.git_pull(lfs=True)
|
| 54 |
+
log_file = os.path.join(dataset_dir, "flag_data.csv")
|
| 55 |
+
return repo, log_file
|
| 56 |
+
|
| 57 |
+
def update(user_choice, data_folder=VIDEO_PATH):
|
| 58 |
envs = parse_envs()
|
| 59 |
env_name = envs[random.randint(0, len(envs)-1)]
|
| 60 |
# choose video
|
|
|
|
| 72 |
current_time = strftime("%Y-%m-%d-%H-%M-%S", gmtime())
|
| 73 |
info = [env_name, user_choice, left, right, current_time]
|
| 74 |
print(info)
|
| 75 |
+
|
| 76 |
+
repo, log_file = get_huggingface_dataset() # flag without using gradio flagging
|
| 77 |
+
with open(log_file, 'a') as file: # incremental change of the file
|
| 78 |
writer_object = writer(file)
|
| 79 |
writer_object.writerow(info)
|
| 80 |
file.close()
|
| 81 |
+
repo.push_to_hub(commit_message=f"Flagged sample at {current_time}")
|
| 82 |
|
| 83 |
+
return left, right
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
def replay(left, right):
|
| 86 |
return left, right
|