Spaces:
Running on Zero
Running on Zero
Upload src/loader.py with huggingface_hub
Browse files- src/loader.py +15 -9
src/loader.py
CHANGED
|
@@ -145,18 +145,24 @@ def prepare_amazon() -> dict:
|
|
| 145 |
books = pd.read_parquet(base / "books.parquet")
|
| 146 |
rat = pd.read_parquet(base / "ratings.parquet")
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
def _first_author(a) -> str:
|
| 149 |
-
if isinstance(a,
|
| 150 |
-
return
|
| 151 |
-
|
|
|
|
| 152 |
|
| 153 |
def _genres(c) -> str:
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
flat += lvl if isinstance(lvl, list) else [lvl]
|
| 158 |
-
return " ".join(dict.fromkeys(str(x) for x in flat))
|
| 159 |
-
return "" if c is None else str(c)
|
| 160 |
|
| 161 |
books = books.copy()
|
| 162 |
books["ISBN"] = books["item_id"].astype(str)
|
|
|
|
| 145 |
books = pd.read_parquet(base / "books.parquet")
|
| 146 |
rat = pd.read_parquet(base / "ratings.parquet")
|
| 147 |
|
| 148 |
+
def _flatten(v):
|
| 149 |
+
if v is None or isinstance(v, str) or not hasattr(v, "__iter__"):
|
| 150 |
+
return [v]
|
| 151 |
+
out = []
|
| 152 |
+
for x in v:
|
| 153 |
+
out.extend(_flatten(x))
|
| 154 |
+
return out
|
| 155 |
+
|
| 156 |
def _first_author(a) -> str:
|
| 157 |
+
if a is None or isinstance(a, str):
|
| 158 |
+
return "" if a is None else a
|
| 159 |
+
flat = _flatten(a)
|
| 160 |
+
return str(flat[0]) if flat else ""
|
| 161 |
|
| 162 |
def _genres(c) -> str:
|
| 163 |
+
flat = _flatten(c)
|
| 164 |
+
cleaned = [str(x) for x in flat if str(x).lower() != "books"]
|
| 165 |
+
return " ".join(dict.fromkeys(cleaned))
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
books = books.copy()
|
| 168 |
books["ISBN"] = books["item_id"].astype(str)
|