Spaces:
Running on Zero
Running on Zero
fix: hide generic citation summaries
Browse filesCo-authored-by: Codex <noreply@openai.com>
- hackathon_advisor/data.py +46 -1
- static/app.js +5 -6
- tests/test_data.py +29 -1
hackathon_advisor/data.py
CHANGED
|
@@ -11,6 +11,16 @@ import re
|
|
| 11 |
|
| 12 |
|
| 13 |
TOKEN_RE = re.compile(r"[a-z0-9][a-z0-9.+_-]*", re.IGNORECASE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
@dataclass(frozen=True)
|
|
@@ -65,6 +75,23 @@ class Project:
|
|
| 65 |
)
|
| 66 |
|
| 67 |
def to_public_dict(self) -> dict:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
return {
|
| 69 |
"id": self.id,
|
| 70 |
"title": self.title,
|
|
@@ -108,6 +135,24 @@ class WhitespaceItem:
|
|
| 108 |
}
|
| 109 |
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
@dataclass(frozen=True)
|
| 112 |
class WhitespaceSeed:
|
| 113 |
label: str
|
|
@@ -354,7 +399,7 @@ def project_snapshot_digest(projects: list[Project], generated_at: str, source:
|
|
| 354 |
payload = {
|
| 355 |
"generated_at": generated_at,
|
| 356 |
"source": source,
|
| 357 |
-
"projects": [project.
|
| 358 |
}
|
| 359 |
encoded = json.dumps(payload, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8")
|
| 360 |
return sha256(encoded).hexdigest()
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
TOKEN_RE = re.compile(r"[a-z0-9][a-z0-9.+_-]*", re.IGNORECASE)
|
| 14 |
+
GENERIC_PUBLIC_TITLE_RE = re.compile(
|
| 15 |
+
r"^(?:my\s+)?build\s+small\s+hackathon$",
|
| 16 |
+
re.IGNORECASE,
|
| 17 |
+
)
|
| 18 |
+
GENERIC_PUBLIC_SUMMARY_RE = re.compile(
|
| 19 |
+
r"(?:\bthis\s+(?:is\s+)?(?:space\s+is\s+for|my\s+submission)\b.*\b(?:build[-\s]*small|hackathon)\b)"
|
| 20 |
+
r"|(?:\bhacka?ton\s+project\b)"
|
| 21 |
+
r"|(?:^\s*todo\s*$)",
|
| 22 |
+
re.IGNORECASE,
|
| 23 |
+
)
|
| 24 |
|
| 25 |
|
| 26 |
@dataclass(frozen=True)
|
|
|
|
| 75 |
)
|
| 76 |
|
| 77 |
def to_public_dict(self) -> dict:
|
| 78 |
+
return {
|
| 79 |
+
"id": self.id,
|
| 80 |
+
"title": public_project_title(self.title),
|
| 81 |
+
"summary": public_project_summary(self.summary),
|
| 82 |
+
"tags": list(self.tags),
|
| 83 |
+
"models": list(self.models),
|
| 84 |
+
"datasets": list(self.datasets),
|
| 85 |
+
"likes": self.likes,
|
| 86 |
+
"sdk": self.sdk,
|
| 87 |
+
"license": self.license,
|
| 88 |
+
"created_at": self.created_at,
|
| 89 |
+
"last_modified": self.last_modified,
|
| 90 |
+
"host": self.host,
|
| 91 |
+
"url": self.url,
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
def to_snapshot_dict(self) -> dict:
|
| 95 |
return {
|
| 96 |
"id": self.id,
|
| 97 |
"title": self.title,
|
|
|
|
| 135 |
}
|
| 136 |
|
| 137 |
|
| 138 |
+
def public_project_title(title: str) -> str:
|
| 139 |
+
cleaned = " ".join(str(title).split())
|
| 140 |
+
if not cleaned:
|
| 141 |
+
return "Untitled project"
|
| 142 |
+
if GENERIC_PUBLIC_TITLE_RE.search(cleaned):
|
| 143 |
+
return "Untitled project"
|
| 144 |
+
return cleaned
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def public_project_summary(summary: str) -> str:
|
| 148 |
+
cleaned = " ".join(str(summary).split())
|
| 149 |
+
if not cleaned:
|
| 150 |
+
return ""
|
| 151 |
+
if GENERIC_PUBLIC_SUMMARY_RE.search(cleaned):
|
| 152 |
+
return ""
|
| 153 |
+
return cleaned
|
| 154 |
+
|
| 155 |
+
|
| 156 |
@dataclass(frozen=True)
|
| 157 |
class WhitespaceSeed:
|
| 158 |
label: str
|
|
|
|
| 399 |
payload = {
|
| 400 |
"generated_at": generated_at,
|
| 401 |
"source": source,
|
| 402 |
+
"projects": [project.to_snapshot_dict() for project in projects],
|
| 403 |
}
|
| 404 |
encoded = json.dumps(payload, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8")
|
| 405 |
return sha256(encoded).hexdigest()
|
static/app.js
CHANGED
|
@@ -765,10 +765,8 @@ function renderProjects(projects) {
|
|
| 765 |
item.href = project.url;
|
| 766 |
item.target = "_blank";
|
| 767 |
item.rel = "noreferrer";
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
<p>${escapeHtml(project.summary || project.id)}</p>
|
| 771 |
-
`;
|
| 772 |
projectsEl.append(item);
|
| 773 |
}
|
| 774 |
}
|
|
@@ -788,9 +786,10 @@ function renderCitations(echoes) {
|
|
| 788 |
item.rel = "noreferrer";
|
| 789 |
item.title = project.title || project.id || "Project citation";
|
| 790 |
const matched = (echo.matched_terms || []).slice(0, 5).join(", ") || "no shared terms";
|
|
|
|
| 791 |
item.innerHTML = `
|
| 792 |
-
<strong>Page ${escapeHtml(echo.page_number || "?")} 路 ${escapeHtml(project.title ||
|
| 793 |
-
|
| 794 |
<span class="matched">${Number(echo.score || 0).toFixed(3)} 路 ${escapeHtml(matched)}</span>
|
| 795 |
`;
|
| 796 |
projectsEl.append(item);
|
|
|
|
| 765 |
item.href = project.url;
|
| 766 |
item.target = "_blank";
|
| 767 |
item.rel = "noreferrer";
|
| 768 |
+
const summary = project.summary ? `<p>${escapeHtml(project.summary)}</p>` : "";
|
| 769 |
+
item.innerHTML = `<strong>${escapeHtml(project.title || "Untitled project")}</strong>${summary}`;
|
|
|
|
|
|
|
| 770 |
projectsEl.append(item);
|
| 771 |
}
|
| 772 |
}
|
|
|
|
| 786 |
item.rel = "noreferrer";
|
| 787 |
item.title = project.title || project.id || "Project citation";
|
| 788 |
const matched = (echo.matched_terms || []).slice(0, 5).join(", ") || "no shared terms";
|
| 789 |
+
const summary = project.summary ? `<p>${escapeHtml(project.summary)}</p>` : "";
|
| 790 |
item.innerHTML = `
|
| 791 |
+
<strong>Page ${escapeHtml(echo.page_number || "?")} 路 ${escapeHtml(project.title || "Untitled project")}</strong>
|
| 792 |
+
${summary}
|
| 793 |
<span class="matched">${Number(echo.score || 0).toFixed(3)} 路 ${escapeHtml(matched)}</span>
|
| 794 |
`;
|
| 795 |
projectsEl.append(item);
|
tests/test_data.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
from pathlib import Path
|
| 2 |
import json
|
| 3 |
|
| 4 |
-
from hackathon_advisor.data import ProjectIndex
|
| 5 |
|
| 6 |
|
| 7 |
def test_project_index_searches_snapshot() -> None:
|
|
@@ -24,6 +24,34 @@ def test_project_index_whitespace() -> None:
|
|
| 24 |
assert all(item.label for item in items)
|
| 25 |
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
def test_project_index_rejects_mismatched_snapshot(tmp_path: Path) -> None:
|
| 28 |
payload = json.loads(Path("data/project_index.json").read_text(encoding="utf-8"))
|
| 29 |
payload["snapshot_generated_at"] = "2000-01-01T00:00:00+00:00"
|
|
|
|
| 1 |
from pathlib import Path
|
| 2 |
import json
|
| 3 |
|
| 4 |
+
from hackathon_advisor.data import Project, ProjectIndex, public_project_summary, public_project_title
|
| 5 |
|
| 6 |
|
| 7 |
def test_project_index_searches_snapshot() -> None:
|
|
|
|
| 24 |
assert all(item.label for item in items)
|
| 25 |
|
| 26 |
|
| 27 |
+
def test_public_project_cards_hide_generic_submission_copy() -> None:
|
| 28 |
+
assert public_project_title("My Build Small Hackathon") == "Untitled project"
|
| 29 |
+
assert public_project_summary("This is my submission for the build-small-hackathon") == ""
|
| 30 |
+
assert public_project_summary("Todo") == ""
|
| 31 |
+
assert public_project_summary("Local-first personal knowledge agent") == "Local-first personal knowledge agent"
|
| 32 |
+
|
| 33 |
+
project = Project(
|
| 34 |
+
id="build-small-hackathon/my-build-small-hackathon",
|
| 35 |
+
title="My Build Small Hackathon",
|
| 36 |
+
summary="This is my submission for the build-small-hackathon",
|
| 37 |
+
tags=(),
|
| 38 |
+
models=(),
|
| 39 |
+
datasets=(),
|
| 40 |
+
likes=0,
|
| 41 |
+
sdk="gradio",
|
| 42 |
+
license="",
|
| 43 |
+
created_at="",
|
| 44 |
+
last_modified="",
|
| 45 |
+
host="",
|
| 46 |
+
url="https://example.test",
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
public = project.to_public_dict()
|
| 50 |
+
|
| 51 |
+
assert public["title"] == "Untitled project"
|
| 52 |
+
assert public["summary"] == ""
|
| 53 |
+
|
| 54 |
+
|
| 55 |
def test_project_index_rejects_mismatched_snapshot(tmp_path: Path) -> None:
|
| 56 |
payload = json.loads(Path("data/project_index.json").read_text(encoding="utf-8"))
|
| 57 |
payload["snapshot_generated_at"] = "2000-01-01T00:00:00+00:00"
|