Spaces:
Running
Running
Rachel Ding commited on
Commit ·
a94b543
1
Parent(s): 86d12ed
NN view: NN1-NN10 from baseline (prompt order), no separate baseline block
Browse files- app.py +7 -17
- dataset_loader.py +16 -36
app.py
CHANGED
|
@@ -14,18 +14,16 @@ TOP1_ID = SAMPLE_IDS[0] if SAMPLE_IDS else None
|
|
| 14 |
|
| 15 |
|
| 16 |
def build_nn_view(sample_id: str | None):
|
| 17 |
-
"""NN view:
|
| 18 |
if not sample_id:
|
| 19 |
-
return (None,) * (
|
| 20 |
data = get_nn_demo_paths(sample_id, top_k=10)
|
| 21 |
out = []
|
| 22 |
-
bl = data.get("baseline", {})
|
| 23 |
-
out.extend([bl.get("spec"), bl.get("bg_wav"), bl.get("fg_wav"), bl.get("m_wav")])
|
| 24 |
for nn in data.get("nn_list", [])[:10]:
|
| 25 |
out.extend([nn.get("spec"), nn.get("m_wav")])
|
| 26 |
-
while len(out) <
|
| 27 |
out.append(None)
|
| 28 |
-
return tuple(out[:
|
| 29 |
|
| 30 |
|
| 31 |
def build_results_view(sample_id: str | None):
|
|
@@ -63,24 +61,16 @@ with gr.Blocks(title="NearestNeighbor Audio Demo", css=".gradio-container { max-
|
|
| 63 |
**Audio labels**: **BG** = background noise | **FG** = generated foreground | **Mix** = BG + FG
|
| 64 |
""")
|
| 65 |
|
| 66 |
-
# ---- NN View:
|
| 67 |
with gr.Column(visible=True) as nn_col:
|
| 68 |
-
gr.Markdown("### Nearest Neighbor: Baseline
|
| 69 |
-
with gr.Row():
|
| 70 |
-
with gr.Column(min_width=180):
|
| 71 |
-
gr.Markdown("**Baseline**")
|
| 72 |
-
nn_bl_img = gr.Image(label="Spec", show_label=False, height=220)
|
| 73 |
-
nn_bl_bg = gr.Audio(label="BG", show_label=True)
|
| 74 |
-
nn_bl_fg = gr.Audio(label="FG", show_label=True)
|
| 75 |
-
nn_bl_m = gr.Audio(label="Mix", show_label=True)
|
| 76 |
-
gr.Markdown("**NN1–NN10**")
|
| 77 |
nn_items = []
|
| 78 |
with gr.Row():
|
| 79 |
for i in range(10):
|
| 80 |
with gr.Column(min_width=120):
|
| 81 |
nn_items.append(gr.Image(label=f"NN{i+1}", show_label=True, height=140))
|
| 82 |
nn_items.append(gr.Audio(label="Mix", show_label=True))
|
| 83 |
-
nn_outputs =
|
| 84 |
|
| 85 |
# ---- Results View: 3 prompts × 4 methods ----
|
| 86 |
with gr.Column(visible=False) as res_col:
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
def build_nn_view(sample_id: str | None):
|
| 17 |
+
"""NN view: NN1-NN10 from baseline (in prompt order). Each has spec + m_wav."""
|
| 18 |
if not sample_id:
|
| 19 |
+
return (None,) * (10 * 2)
|
| 20 |
data = get_nn_demo_paths(sample_id, top_k=10)
|
| 21 |
out = []
|
|
|
|
|
|
|
| 22 |
for nn in data.get("nn_list", [])[:10]:
|
| 23 |
out.extend([nn.get("spec"), nn.get("m_wav")])
|
| 24 |
+
while len(out) < 20:
|
| 25 |
out.append(None)
|
| 26 |
+
return tuple(out[:20])
|
| 27 |
|
| 28 |
|
| 29 |
def build_results_view(sample_id: str | None):
|
|
|
|
| 61 |
**Audio labels**: **BG** = background noise | **FG** = generated foreground | **Mix** = BG + FG
|
| 62 |
""")
|
| 63 |
|
| 64 |
+
# ---- NN View: NN1-NN10 from baseline (in prompt order) ----
|
| 65 |
with gr.Column(visible=True) as nn_col:
|
| 66 |
+
gr.Markdown("### Nearest Neighbor: Baseline outputs (top 10 prompts)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
nn_items = []
|
| 68 |
with gr.Row():
|
| 69 |
for i in range(10):
|
| 70 |
with gr.Column(min_width=120):
|
| 71 |
nn_items.append(gr.Image(label=f"NN{i+1}", show_label=True, height=140))
|
| 72 |
nn_items.append(gr.Audio(label="Mix", show_label=True))
|
| 73 |
+
nn_outputs = nn_items
|
| 74 |
|
| 75 |
# ---- Results View: 3 prompts × 4 methods ----
|
| 76 |
with gr.Column(visible=False) as res_col:
|
dataset_loader.py
CHANGED
|
@@ -84,57 +84,37 @@ def _collect_block(file_list: list, folder_prefix: str) -> dict:
|
|
| 84 |
|
| 85 |
def get_nn_demo_paths(bid: str, top_k: int = 10) -> dict:
|
| 86 |
"""
|
| 87 |
-
For NN view:
|
| 88 |
-
Returns {
|
| 89 |
"""
|
| 90 |
inner = f"{ROOT_PREFIX}{bid}/{bid}"
|
| 91 |
prompts = _load_json_from_repo(f"{inner}/temp_retrieval.json")
|
| 92 |
if not prompts:
|
| 93 |
prompts = _load_json_from_repo(f"{inner}/natural_prompts.json")
|
| 94 |
if not prompts:
|
| 95 |
-
return {"
|
| 96 |
|
| 97 |
files = _find_files(inner)
|
| 98 |
baseline_inner = f"{inner}/baseline"
|
| 99 |
baseline_files = _find_files(baseline_inner) if any(f.startswith(baseline_inner) for f in files) else []
|
| 100 |
|
| 101 |
-
# Baseline: first baseline folder (generated_baseline_01_*)
|
| 102 |
-
baseline_block = {"spec": None, "bg_wav": None, "fg_wav": None, "m_wav": None}
|
| 103 |
-
for f in baseline_files:
|
| 104 |
-
parts = f.replace(baseline_inner + "/", "").split("/")
|
| 105 |
-
if parts and parts[0].startswith("generated_baseline_01_"):
|
| 106 |
-
full_prefix = baseline_inner + "/" + parts[0]
|
| 107 |
-
baseline_block = _collect_block(baseline_files, full_prefix)
|
| 108 |
-
break
|
| 109 |
-
|
| 110 |
nn_list = []
|
| 111 |
for i, p in enumerate(prompts[:top_k]):
|
| 112 |
prompt = p.get("prompt", "")
|
| 113 |
sim = p.get("similarity_score", p.get("retrieval_score"))
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
for f in
|
| 117 |
-
parts = f.replace(
|
| 118 |
-
if
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
spec_path = f
|
| 128 |
-
nn_list.append({
|
| 129 |
-
"fg_wav": _download_file(fg_path) if fg_path else None,
|
| 130 |
-
"spec": _download_file(spec_path) if spec_path else None,
|
| 131 |
-
"bg_wav": _download_file(bg_path) if bg_path else None,
|
| 132 |
-
"m_wav": _download_file(m_path) if m_path else None,
|
| 133 |
-
"prompt": prompt,
|
| 134 |
-
"similarity": sim,
|
| 135 |
-
})
|
| 136 |
-
|
| 137 |
-
return {"baseline": baseline_block, "nn_list": nn_list}
|
| 138 |
|
| 139 |
|
| 140 |
def get_noise_demo_paths(bid: str) -> dict:
|
|
|
|
| 84 |
|
| 85 |
def get_nn_demo_paths(bid: str, top_k: int = 10) -> dict:
|
| 86 |
"""
|
| 87 |
+
For NN view: NN1-NN10 from baseline (generated_baseline_01, 02, ..., 10) in prompt order.
|
| 88 |
+
Returns {nn_list: [{spec, bg_wav, fg_wav, m_wav, prompt, similarity}, ...]}.
|
| 89 |
"""
|
| 90 |
inner = f"{ROOT_PREFIX}{bid}/{bid}"
|
| 91 |
prompts = _load_json_from_repo(f"{inner}/temp_retrieval.json")
|
| 92 |
if not prompts:
|
| 93 |
prompts = _load_json_from_repo(f"{inner}/natural_prompts.json")
|
| 94 |
if not prompts:
|
| 95 |
+
return {"nn_list": []}
|
| 96 |
|
| 97 |
files = _find_files(inner)
|
| 98 |
baseline_inner = f"{inner}/baseline"
|
| 99 |
baseline_files = _find_files(baseline_inner) if any(f.startswith(baseline_inner) for f in files) else []
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
nn_list = []
|
| 102 |
for i, p in enumerate(prompts[:top_k]):
|
| 103 |
prompt = p.get("prompt", "")
|
| 104 |
sim = p.get("similarity_score", p.get("retrieval_score"))
|
| 105 |
+
bl_prefix = f"generated_baseline_{i+1:02d}_"
|
| 106 |
+
block = {"spec": None, "bg_wav": None, "fg_wav": None, "m_wav": None}
|
| 107 |
+
for f in baseline_files:
|
| 108 |
+
parts = f.replace(baseline_inner + "/", "").split("/")
|
| 109 |
+
if parts and parts[0].startswith(bl_prefix):
|
| 110 |
+
full_prefix = baseline_inner + "/" + parts[0]
|
| 111 |
+
block = _collect_block(baseline_files, full_prefix)
|
| 112 |
+
break
|
| 113 |
+
block["prompt"] = prompt
|
| 114 |
+
block["similarity"] = sim
|
| 115 |
+
nn_list.append(block)
|
| 116 |
+
|
| 117 |
+
return {"nn_list": nn_list}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
|
| 120 |
def get_noise_demo_paths(bid: str) -> dict:
|