Spaces:
Sleeping
Sleeping
Commit
·
e0df362
1
Parent(s):
c5fdd0a
fix pushing data on huggingface dataset
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import random
|
|
| 4 |
import os
|
| 5 |
import json
|
| 6 |
from pathlib import Path
|
| 7 |
-
from huggingface_hub import CommitScheduler
|
| 8 |
|
| 9 |
from src.utils import load_words, load_image_and_saliency, load_example_images
|
| 10 |
from src.style import css
|
|
@@ -129,23 +129,22 @@ def main():
|
|
| 129 |
pass
|
| 130 |
|
| 131 |
def save_results(answers):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
json_file_results = config['results']['exp1_dir']
|
| 133 |
JSON_DATASET_DIR = Path("json_dataset")
|
| 134 |
JSON_DATASET_DIR.mkdir(parents=True, exist_ok=True)
|
| 135 |
JSON_DATASET_PATH = JSON_DATASET_DIR / json_file_results
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
with JSON_DATASET_PATH.open("a") as f:
|
| 145 |
-
json.dump({
|
| 146 |
-
"user_id": user_id,
|
| 147 |
-
"answer": {i: answer[i] for i in range(len(answer))}
|
| 148 |
-
}, f)
|
| 149 |
|
| 150 |
def add_answer(dropdown1,dropdown2,dropdown3,dropdown4, answers):
|
| 151 |
rank = [dropdown1,dropdown2,dropdown3,dropdown4]
|
|
|
|
| 4 |
import os
|
| 5 |
import json
|
| 6 |
from pathlib import Path
|
| 7 |
+
from huggingface_hub import CommitScheduler, HfApi
|
| 8 |
|
| 9 |
from src.utils import load_words, load_image_and_saliency, load_example_images
|
| 10 |
from src.style import css
|
|
|
|
| 129 |
pass
|
| 130 |
|
| 131 |
def save_results(answers):
|
| 132 |
+
api = HfApi()
|
| 133 |
+
token = os.getenv("HUGGINGFACE_TOKEN")
|
| 134 |
+
api.login(token=token)
|
| 135 |
+
|
| 136 |
json_file_results = config['results']['exp1_dir']
|
| 137 |
JSON_DATASET_DIR = Path("json_dataset")
|
| 138 |
JSON_DATASET_DIR.mkdir(parents=True, exist_ok=True)
|
| 139 |
JSON_DATASET_PATH = JSON_DATASET_DIR / json_file_results
|
| 140 |
+
|
| 141 |
+
info_to_push = {
|
| 142 |
+
"user_id": time.time(),
|
| 143 |
+
"answer": {i: answer[i] for i in range(len(answer))}}
|
| 144 |
+
|
| 145 |
+
# use api to push the results
|
| 146 |
+
api.push_to_hub(info_to_push, json_file_results, use_temp_dir=True)
|
| 147 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
def add_answer(dropdown1,dropdown2,dropdown3,dropdown4, answers):
|
| 150 |
rank = [dropdown1,dropdown2,dropdown3,dropdown4]
|