Download utils.py from bharatverse11/PlayslistCreationEngine: direct link, hf CLI and curl.
- Browser
- Download file 489 Bytes
-
https://huggingface.co/spaces/bharatverse11/PlayslistCreationEngine/resolve/main/utils.py
- Command line
-
hf download hf://spaces/bharatverse11/PlayslistCreationEngine/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/bharatverse11/PlayslistCreationEngine/resolve/main/utils.py
489 Bytes
| def deduplicate_tracks(tracks): | |
| seen = set() | |
| unique = [] | |
| for t in tracks: | |
| if t["id"] not in seen: | |
| seen.add(t["id"]) | |
| unique.append(t) | |
| return unique | |
| def diversify_tracks(tracks): | |
| result = [] | |
| artist_count = {} | |
| for t in tracks: | |
| artist = t["artists"][0]["name"] | |
| count = artist_count.get(artist, 0) | |
| if count < 2: | |
| result.append(t) | |
| artist_count[artist] = count + 1 | |
| return result | |