Update utils.py
Browse files
utils.py
CHANGED
|
@@ -17,6 +17,38 @@ from constants import (
|
|
| 17 |
api = HfApi(token=HF_TOKEN)
|
| 18 |
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
def init_repo():
|
| 21 |
try:
|
| 22 |
api.repo_info(REPO_ID, repo_type="dataset")
|
|
@@ -62,13 +94,7 @@ def load_data():
|
|
| 62 |
)
|
| 63 |
df = df.drop(columns=["link"])
|
| 64 |
|
| 65 |
-
df["license"] = df["license"].apply(
|
| 66 |
-
lambda x: "Открытая"
|
| 67 |
-
if any(
|
| 68 |
-
term in x.lower() for term in ["mit", "apache", "bsd", "gpl", "open"]
|
| 69 |
-
)
|
| 70 |
-
else "Закрытая"
|
| 71 |
-
)
|
| 72 |
|
| 73 |
df["rank"] = df["rank"].apply(
|
| 74 |
lambda r: "🥇" if r == 1 else "🥈" if r == 2 else "🥉" if r == 3 else str(r)
|
|
|
|
| 17 |
api = HfApi(token=HF_TOKEN)
|
| 18 |
|
| 19 |
|
| 20 |
+
OPEN_LICENSE_KEYWORDS = {
|
| 21 |
+
"mit", "apache", "apache-2", "apache-2.0",
|
| 22 |
+
"bsd", "bsd-2", "bsd-3", "bsd-2-clause", "bsd-3-clause",
|
| 23 |
+
"isc", "mpl", "mpl-2.0",
|
| 24 |
+
"lgpl", "lgpl-2.1", "lgpl-3.0",
|
| 25 |
+
"gpl", "gpl-2.0", "gpl-3.0", "agpl", "agpl-3.0",
|
| 26 |
+
"epl", "epl-2.0", "cddl", "cddl-1.0", "cddl-1.1",
|
| 27 |
+
"bsl", "bsl-1.0", "boost", "zlib", "unlicense", "artistic-2.0",
|
| 28 |
+
"cc0", "cc0-1.0",
|
| 29 |
+
"cc-by", "cc-by-3.0", "cc-by-4.0",
|
| 30 |
+
"cc-by-sa", "cc-by-sa-3.0", "cc-by-sa-4.0",
|
| 31 |
+
"openrail", "openrail-m", "bigscience openrail", "bigscience openrail-m",
|
| 32 |
+
"open-source", "opensource", "open source"
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
RESTRICTIVE_LICENSE_KEYWORDS = {
|
| 36 |
+
"cc-by-nc", "cc-by-nc-sa", "cc-nc", "nc-sa", "nc-nd",
|
| 37 |
+
"cc-by-nd", "cc-nd", "no-derivatives", "no derivatives",
|
| 38 |
+
"non-commercial", "noncommercial", "research-only", "research only",
|
| 39 |
+
"llama", "llama-2", "community license",
|
| 40 |
+
"proprietary", "closed", "unknown", "custom"
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
def is_open_license(license_str: str) -> bool:
|
| 44 |
+
s = (str(license_str) if license_str is not None else "").strip().lower()
|
| 45 |
+
if not s:
|
| 46 |
+
return False
|
| 47 |
+
if any(pat in s for pat in RESTRICTIVE_LICENSE_KEYWORDS):
|
| 48 |
+
return False
|
| 49 |
+
return any(pat in s for pat in OPEN_LICENSE_KEYWORDS)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
def init_repo():
|
| 53 |
try:
|
| 54 |
api.repo_info(REPO_ID, repo_type="dataset")
|
|
|
|
| 94 |
)
|
| 95 |
df = df.drop(columns=["link"])
|
| 96 |
|
| 97 |
+
df["license"] = df["license"].apply(lambda x: "Открытая" if is_open_license(x) else "Закрытая")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
df["rank"] = df["rank"].apply(
|
| 100 |
lambda r: "🥇" if r == 1 else "🥈" if r == 2 else "🥉" if r == 3 else str(r)
|