Spaces:
Running
Running
Tuan Tran
commited on
Commit
·
9e6ac41
1
Parent(s):
ab4ab85
update helper functions
Browse files- backend/app.py +15 -26
- backend/config.py +72 -86
- backend/examples.py +0 -1
backend/app.py
CHANGED
@@ -1,33 +1,22 @@
|
|
1 |
-
from backend.config import (
|
2 |
-
ABS_DATASET_DOMAIN,
|
3 |
-
get_dataset_config,
|
4 |
-
get_datasets,
|
5 |
-
)
|
6 |
-
from backend.descriptions import (
|
7 |
-
DATASET_DESCRIPTIONS,
|
8 |
-
DESCRIPTIONS,
|
9 |
-
METRIC_DESCRIPTIONS,
|
10 |
-
MODEL_DESCRIPTIONS,
|
11 |
-
)
|
12 |
-
from backend.examples import (
|
13 |
-
get_examples_tab,
|
14 |
-
)
|
15 |
-
from flask import Flask, Response, send_from_directory, request
|
16 |
-
from flask_cors import CORS
|
17 |
-
import os
|
18 |
-
import logging
|
19 |
-
import pandas as pd
|
20 |
import json
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
get_old_format_dataframe,
|
25 |
-
) # Import your function
|
26 |
import typing as tp
|
27 |
-
import
|
28 |
from urllib.parse import unquote
|
29 |
-
import mimetypes
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
logger = logging.getLogger(__name__)
|
33 |
if not logger.hasHandlers():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import json
|
2 |
+
import logging
|
3 |
+
import mimetypes
|
4 |
+
import os
|
|
|
|
|
5 |
import typing as tp
|
6 |
+
from io import StringIO
|
7 |
from urllib.parse import unquote
|
|
|
8 |
|
9 |
+
import pandas as pd
|
10 |
+
import requests
|
11 |
+
from flask import Flask, Response, request, send_from_directory
|
12 |
+
from flask_cors import CORS
|
13 |
+
from tools import (get_leaderboard_filters, # Import your function
|
14 |
+
get_old_format_dataframe)
|
15 |
+
|
16 |
+
from backend.config import ABS_DATASET_DOMAIN, get_dataset_config, get_datasets
|
17 |
+
from backend.descriptions import (DATASET_DESCRIPTIONS, DESCRIPTIONS,
|
18 |
+
METRIC_DESCRIPTIONS, MODEL_DESCRIPTIONS)
|
19 |
+
from backend.examples import get_examples_tab
|
20 |
|
21 |
logger = logging.getLogger(__name__)
|
22 |
if not logger.hasHandlers():
|
backend/config.py
CHANGED
@@ -1,5 +1,10 @@
|
|
1 |
# Change these values to match your dataset structure if loading locally or from a different source.
|
2 |
# IMPORTANT: When running from docker more setup is required (e.g. on Huggingface)
|
|
|
|
|
|
|
|
|
|
|
3 |
ABS_DATASET_DOMAIN = "https://dl.fbaipublicfiles.com"
|
4 |
|
5 |
# Sample dataset domain and path for local loading
|
@@ -8,10 +13,8 @@ ABS_DATASET_DOMAIN = "https://dl.fbaipublicfiles.com"
|
|
8 |
|
9 |
ABS_DATASET_PATH = f"{ABS_DATASET_DOMAIN}/omnisealbench/"
|
10 |
|
11 |
-
|
12 |
-
"
|
13 |
-
"type": "audio",
|
14 |
-
"path": ABS_DATASET_PATH,
|
15 |
"first_cols": [
|
16 |
"snr",
|
17 |
"sisnr",
|
@@ -49,79 +52,7 @@ DATASET_CONFIGS = {
|
|
49 |
"shush",
|
50 |
],
|
51 |
},
|
52 |
-
"
|
53 |
-
"type": "audio",
|
54 |
-
"path": ABS_DATASET_PATH,
|
55 |
-
"first_cols": ["snr", "sisnr", "stoi", "pesq"],
|
56 |
-
"attack_scores": ["bit_acc", "log10_p_value", "TPR", "FPR"],
|
57 |
-
"categories": {
|
58 |
-
"speed": "Time",
|
59 |
-
"updownresample": "Time",
|
60 |
-
"echo": "Time",
|
61 |
-
"random_noise": "Amplitude",
|
62 |
-
"lowpass_filter": "Amplitude",
|
63 |
-
"highpass_filter": "Amplitude",
|
64 |
-
"bandpass_filter": "Amplitude",
|
65 |
-
"smooth": "Amplitude",
|
66 |
-
"boost_audio": "Amplitude",
|
67 |
-
"duck_audio": "Amplitude",
|
68 |
-
"shush": "Amplitude",
|
69 |
-
"pink_noise": "Amplitude",
|
70 |
-
"aac_compression": "Compression",
|
71 |
-
"mp3_compression": "Compression",
|
72 |
-
},
|
73 |
-
"attacks_with_variations": [
|
74 |
-
"random_noise",
|
75 |
-
"lowpass_filter",
|
76 |
-
"highpass_filter",
|
77 |
-
"boost_audio",
|
78 |
-
"duck_audio",
|
79 |
-
"shush",
|
80 |
-
],
|
81 |
-
},
|
82 |
-
"val2014_1k_v2/image": {
|
83 |
-
"type": "image",
|
84 |
-
"path": ABS_DATASET_PATH,
|
85 |
-
"first_cols": ["psnr", "ssim", "lpips", "decoder_time"],
|
86 |
-
"attack_scores": ["bit_acc", "log10_p_value", "TPR", "FPR"],
|
87 |
-
"categories": {
|
88 |
-
"proportion": "Geometric",
|
89 |
-
"collage": "Inpainting",
|
90 |
-
"center_crop": "Geometric",
|
91 |
-
"rotate": "Geometric",
|
92 |
-
"jpeg": "Compression",
|
93 |
-
"brightness": "Visual",
|
94 |
-
"contrast": "Visual",
|
95 |
-
"saturation": "Visual",
|
96 |
-
"sharpness": "Visual",
|
97 |
-
"resize": "Geometric",
|
98 |
-
"overlay_text": "Inpainting",
|
99 |
-
"hflip": "Geometric",
|
100 |
-
"perspective": "Geometric",
|
101 |
-
"median_filter": "Visual",
|
102 |
-
"hue": "Visual",
|
103 |
-
"gaussian_blur": "Visual",
|
104 |
-
"comb": "Mixed",
|
105 |
-
"avg": "Averages",
|
106 |
-
"none": "Baseline",
|
107 |
-
},
|
108 |
-
"attacks_with_variations": [
|
109 |
-
"center_crop",
|
110 |
-
"jpeg",
|
111 |
-
"brightness",
|
112 |
-
"contrast",
|
113 |
-
"saturation",
|
114 |
-
"sharpness",
|
115 |
-
"resize",
|
116 |
-
"perspective",
|
117 |
-
"median_filter",
|
118 |
-
"hue",
|
119 |
-
"gaussian_blur",
|
120 |
-
],
|
121 |
-
},
|
122 |
-
"sa_1b_val_1k/image": {
|
123 |
-
"type": "image",
|
124 |
-
"path": ABS_DATASET_PATH,
|
125 |
"first_cols": ["psnr", "ssim", "lpips", "decoder_time"],
|
126 |
"attack_scores": ["bit_acc", "log10_p_value", "TPR", "FPR"],
|
127 |
"categories": {
|
@@ -159,9 +90,7 @@ DATASET_CONFIGS = {
|
|
159 |
"gaussian_blur",
|
160 |
],
|
161 |
},
|
162 |
-
"
|
163 |
-
"type": "video",
|
164 |
-
"path": ABS_DATASET_PATH,
|
165 |
"first_cols": ["psnr", "ssim", "msssim", "lpips", "vmaf", "decoder_time"],
|
166 |
"attack_scores": ["bit_acc", "log10_p_value", "TPR", "FPR"],
|
167 |
"categories": {
|
@@ -198,12 +127,20 @@ DATASET_CONFIGS = {
|
|
198 |
"H264rgb",
|
199 |
"H265",
|
200 |
],
|
201 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
}
|
203 |
|
|
|
204 |
EXAMPLE_CONFIGS = {
|
205 |
"audio": {
|
206 |
-
"type": "audio",
|
207 |
"dataset_name": "voxpopuli_1k",
|
208 |
"path": ABS_DATASET_PATH,
|
209 |
"db_key": "voxpopuli",
|
@@ -226,24 +163,73 @@ EXAMPLE_CONFIGS = {
|
|
226 |
}
|
227 |
|
228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
def get_datasets():
|
230 |
grouped = {"audio": [], "image": [], "video": []}
|
231 |
for name, cfg in DATASET_CONFIGS.items():
|
232 |
dtype = cfg.get("type")
|
233 |
if dtype in grouped:
|
234 |
grouped[dtype].append(name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
return grouped
|
236 |
|
237 |
|
238 |
def get_example_config(type):
|
239 |
-
if type in EXAMPLE_CONFIGS:
|
240 |
-
return EXAMPLE_CONFIGS[type]
|
241 |
-
else:
|
242 |
raise ValueError(f"Unknown example type: {type}")
|
243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
|
245 |
def get_dataset_config(dataset_name):
|
246 |
if dataset_name in DATASET_CONFIGS:
|
247 |
-
|
|
|
|
|
|
|
248 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
raise ValueError(f"Unknown dataset: {dataset_name}")
|
|
|
1 |
# Change these values to match your dataset structure if loading locally or from a different source.
|
2 |
# IMPORTANT: When running from docker more setup is required (e.g. on Huggingface)
|
3 |
+
import os
|
4 |
+
from collections import defaultdict
|
5 |
+
from copy import deepcopy
|
6 |
+
from typing import Any, Dict
|
7 |
+
|
8 |
ABS_DATASET_DOMAIN = "https://dl.fbaipublicfiles.com"
|
9 |
|
10 |
# Sample dataset domain and path for local loading
|
|
|
13 |
|
14 |
ABS_DATASET_PATH = f"{ABS_DATASET_DOMAIN}/omnisealbench/"
|
15 |
|
16 |
+
MODALITY_CONFIG_CONSTANTS = {
|
17 |
+
"audio": {
|
|
|
|
|
18 |
"first_cols": [
|
19 |
"snr",
|
20 |
"sisnr",
|
|
|
52 |
"shush",
|
53 |
],
|
54 |
},
|
55 |
+
"image": {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
"first_cols": ["psnr", "ssim", "lpips", "decoder_time"],
|
57 |
"attack_scores": ["bit_acc", "log10_p_value", "TPR", "FPR"],
|
58 |
"categories": {
|
|
|
90 |
"gaussian_blur",
|
91 |
],
|
92 |
},
|
93 |
+
"video": {
|
|
|
|
|
94 |
"first_cols": ["psnr", "ssim", "msssim", "lpips", "vmaf", "decoder_time"],
|
95 |
"attack_scores": ["bit_acc", "log10_p_value", "TPR", "FPR"],
|
96 |
"categories": {
|
|
|
127 |
"H264rgb",
|
128 |
"H265",
|
129 |
],
|
130 |
+
}
|
131 |
+
}
|
132 |
+
|
133 |
+
DATASET_CONFIGS = {
|
134 |
+
"voxpopuli_1k/audio": {"type": "audio", "path": ABS_DATASET_PATH},
|
135 |
+
"ravdess_1k/audio": {"type": "audio", "path": ABS_DATASET_PATH},
|
136 |
+
"val2014_1k_v2/image": {"type": "image", "path": ABS_DATASET_PATH},
|
137 |
+
"sa_1b_val_1k/image": {"type": "image", "path": ABS_DATASET_PATH},
|
138 |
+
"sav_val_full_v2/video": {"type": "video", "path": ABS_DATASET_PATH},
|
139 |
}
|
140 |
|
141 |
+
|
142 |
EXAMPLE_CONFIGS = {
|
143 |
"audio": {
|
|
|
144 |
"dataset_name": "voxpopuli_1k",
|
145 |
"path": ABS_DATASET_PATH,
|
146 |
"db_key": "voxpopuli",
|
|
|
163 |
}
|
164 |
|
165 |
|
166 |
+
def get_user_dataset():
|
167 |
+
datasets = defaultdict(list)
|
168 |
+
user_data_dir = os.getenv("OMNISEAL_LEADERBOARD_DATA", "./data")
|
169 |
+
if user_data_dir:
|
170 |
+
for user_data in os.listdir(user_data_dir):
|
171 |
+
if not os.path.isdir(os.path.join(user_data_dir, user_data)):
|
172 |
+
continue
|
173 |
+
user_dtype = os.listdir(os.path.join(user_data_dir, user_data, "examples"))[0]
|
174 |
+
datasets[user_dtype].append(user_data + "/" + user_dtype)
|
175 |
+
|
176 |
+
return datasets
|
177 |
+
|
178 |
+
|
179 |
def get_datasets():
|
180 |
grouped = {"audio": [], "image": [], "video": []}
|
181 |
for name, cfg in DATASET_CONFIGS.items():
|
182 |
dtype = cfg.get("type")
|
183 |
if dtype in grouped:
|
184 |
grouped[dtype].append(name)
|
185 |
+
|
186 |
+
# Add user datasets
|
187 |
+
user_datasets = get_user_dataset()
|
188 |
+
for dtype, user_names in user_datasets.items():
|
189 |
+
if dtype in grouped:
|
190 |
+
_names = [name for name in user_names if name not in grouped[dtype]]
|
191 |
+
grouped[dtype].extend(_names)
|
192 |
return grouped
|
193 |
|
194 |
|
195 |
def get_example_config(type):
|
196 |
+
if type not in EXAMPLE_CONFIGS:
|
|
|
|
|
197 |
raise ValueError(f"Unknown example type: {type}")
|
198 |
|
199 |
+
examples_config: Dict[str, Any] = deepcopy(EXAMPLE_CONFIGS[type])
|
200 |
+
|
201 |
+
user_datasets = get_user_dataset()
|
202 |
+
user_data_dir = os.getenv("OMNISEAL_LEADERBOARD_DATA", "./data")
|
203 |
+
if len(user_datasets) > 0:
|
204 |
+
assert user_data_dir, f"OMNISEAL_LEADERBOARD_DATA is reset during loading the examples for {type}. Please set it correctly"
|
205 |
+
for dtype, user_names in user_datasets.items():
|
206 |
+
if dtype == type:
|
207 |
+
dataset_name = user_names[0].split("/")[0]
|
208 |
+
path = user_data_dir + "/"
|
209 |
+
examples_config = {
|
210 |
+
"dataset_name": dataset_name,
|
211 |
+
"path": path,
|
212 |
+
"db_key": dataset_name,
|
213 |
+
}
|
214 |
+
return examples_config
|
215 |
+
|
216 |
|
217 |
def get_dataset_config(dataset_name):
|
218 |
if dataset_name in DATASET_CONFIGS:
|
219 |
+
cfg = DATASET_CONFIGS[dataset_name]
|
220 |
+
extra_cfg = MODALITY_CONFIG_CONSTANTS.get(cfg["type"], {})
|
221 |
+
cfg.update(extra_cfg)
|
222 |
+
return cfg
|
223 |
else:
|
224 |
+
modality = dataset_name.split("/")[-1]
|
225 |
+
user_dataset = get_user_dataset()
|
226 |
+
if dataset_name in user_dataset.get(modality, []):
|
227 |
+
cfg = {
|
228 |
+
"type": modality,
|
229 |
+
"path": os.getenv("OMNISEAL_LEADERBOARD_DATA"),
|
230 |
+
}
|
231 |
+
extra_cfg = MODALITY_CONFIG_CONSTANTS.get(cfg["type"], {})
|
232 |
+
cfg.update(extra_cfg)
|
233 |
+
return cfg
|
234 |
+
|
235 |
raise ValueError(f"Unknown dataset: {dataset_name}")
|
backend/examples.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import ast
|
2 |
import json
|
3 |
import re
|
4 |
-
|
5 |
from pathlib import Path
|
6 |
|
7 |
import requests
|
|
|
1 |
import ast
|
2 |
import json
|
3 |
import re
|
|
|
4 |
from pathlib import Path
|
5 |
|
6 |
import requests
|