Spaces:
Runtime error
Runtime error
Commit ·
df68270
1
Parent(s): def517a
allow to survey with particular methods
Browse files- app.py +29 -15
- config.yaml +5 -0
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from argparse import ArgumentParser
|
| 2 |
-
import os, threading, time
|
| 3 |
from dataclasses import dataclass
|
| 4 |
from datetime import datetime, timezone
|
| 5 |
from pprint import pprint
|
|
@@ -58,7 +58,8 @@ class SurveyEngine:
|
|
| 58 |
radius_size=gr.themes.sizes.radius_md,
|
| 59 |
)
|
| 60 |
|
| 61 |
-
|
|
|
|
| 62 |
|
| 63 |
def _start_periodic_sync(self):
|
| 64 |
def _upload_periodically(path_local, path_remote):
|
|
@@ -101,7 +102,14 @@ class SurveyEngine:
|
|
| 101 |
|
| 102 |
def _get_all_video_paths(self):
|
| 103 |
video_dir = f"{self.local_dir}/video"
|
|
|
|
| 104 |
method_list = sorted(os.listdir(video_dir))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
video_name_list = sorted(os.listdir(f"{video_dir}/{method_list[0]}"))
|
| 106 |
|
| 107 |
N_prompts = len(video_name_list)
|
|
@@ -549,23 +557,29 @@ class SurveyEngine:
|
|
| 549 |
demo.launch(share=self.args.share, show_api=False)
|
| 550 |
|
| 551 |
|
| 552 |
-
|
| 553 |
parser = ArgumentParser()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 554 |
parser.add_argument("--debug", action="store_true")
|
| 555 |
parser.add_argument("--share", action="store_true")
|
| 556 |
-
parser.add_argument(
|
| 557 |
-
"--period_upload",
|
| 558 |
-
type=int,
|
| 559 |
-
default=300,
|
| 560 |
-
help="Period (sec) to upload response files in seconds, 300sec=5min",
|
| 561 |
-
)
|
| 562 |
-
parser.add_argument(
|
| 563 |
-
"--period_squash",
|
| 564 |
-
type=int,
|
| 565 |
-
default=43200,
|
| 566 |
-
help="Period (sec) to squash commits in seconds, 43200sec=12h",
|
| 567 |
-
)
|
| 568 |
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 569 |
|
| 570 |
survey_engine = SurveyEngine(args)
|
| 571 |
survey_engine.main()
|
|
|
|
| 1 |
from argparse import ArgumentParser
|
| 2 |
+
import os, threading, time, yaml
|
| 3 |
from dataclasses import dataclass
|
| 4 |
from datetime import datetime, timezone
|
| 5 |
from pprint import pprint
|
|
|
|
| 58 |
radius_size=gr.themes.sizes.radius_md,
|
| 59 |
)
|
| 60 |
|
| 61 |
+
if not args.no_sync:
|
| 62 |
+
self._start_periodic_sync()
|
| 63 |
|
| 64 |
def _start_periodic_sync(self):
|
| 65 |
def _upload_periodically(path_local, path_remote):
|
|
|
|
| 102 |
|
| 103 |
def _get_all_video_paths(self):
|
| 104 |
video_dir = f"{self.local_dir}/video"
|
| 105 |
+
|
| 106 |
method_list = sorted(os.listdir(video_dir))
|
| 107 |
+
|
| 108 |
+
# filter methods
|
| 109 |
+
if len(self.args.method_filter) > 0:
|
| 110 |
+
method_filter = np.array(self.args.method_filter)
|
| 111 |
+
method_list = np.intersect1d(method_list, method_filter)
|
| 112 |
+
|
| 113 |
video_name_list = sorted(os.listdir(f"{video_dir}/{method_list[0]}"))
|
| 114 |
|
| 115 |
N_prompts = len(video_name_list)
|
|
|
|
| 557 |
demo.launch(share=self.args.share, show_api=False)
|
| 558 |
|
| 559 |
|
| 560 |
+
def parse_args():
|
| 561 |
parser = ArgumentParser()
|
| 562 |
+
|
| 563 |
+
# use this config as HF space does not take args
|
| 564 |
+
parser.add_argument("--config", type=str, default="config.yaml")
|
| 565 |
+
|
| 566 |
+
# these args are useful for local debugging
|
| 567 |
parser.add_argument("--debug", action="store_true")
|
| 568 |
parser.add_argument("--share", action="store_true")
|
| 569 |
+
parser.add_argument("--no_sync", action="store_true")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 570 |
args = parser.parse_args()
|
| 571 |
+
|
| 572 |
+
with open(args.config, "r") as f:
|
| 573 |
+
config = yaml.safe_load(f)
|
| 574 |
+
|
| 575 |
+
for key, value in config.items():
|
| 576 |
+
setattr(args, key, value)
|
| 577 |
+
pprint(vars(args))
|
| 578 |
+
return args
|
| 579 |
+
|
| 580 |
+
|
| 581 |
+
if __name__ == "__main__":
|
| 582 |
+
args = parse_args()
|
| 583 |
|
| 584 |
survey_engine = SurveyEngine(args)
|
| 585 |
survey_engine.main()
|
config.yaml
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
method_filter:
|
| 2 |
+
- method_A
|
| 3 |
+
- method_B
|
| 4 |
+
period_upload: 300 # Period (sec) to upload response files in seconds, 300sec=5min
|
| 5 |
+
period_squash: 43200 # Period (sec) to squash commits in seconds, 43200sec=12h
|