Spaces:
Paused
Paused
Download services/avatar.py from igardner/StockAnalysis: direct link, hf CLI and curl.
- Browser
- Download file 976 Bytes
-
https://huggingface.co/spaces/igardner/StockAnalysis/resolve/main/services/avatar.py
- Command line
-
hf download hf://spaces/igardner/StockAnalysis/services/avatar.py
-
curl -L -o avatar.py https://huggingface.co/spaces/igardner/StockAnalysis/resolve/main/services/avatar.py
976 Bytes
| from config import Config | |
| import random | |
| class AvatarService: | |
| def get_styles(): | |
| return Config.AVATAR_STYLES_CC0 | |
| def get_backgrounds(): | |
| return Config.AVATAR_BACKGROUNDS | |
| def build_url(style=None, seed=None, bg=None, format="svg"): | |
| styles = AvatarService.get_styles() | |
| style = style if style in styles else random.choice(styles) | |
| if not seed: | |
| seed = str(random.randint(100000, 999999)) | |
| base = f"https://api.dicebear.com/7.x/{style}/{format}" | |
| url = f"{base}?seed={seed}" | |
| if bg and bg != "transparent": | |
| url += f"&backgroundColor={bg}" | |
| return url | |
| def random_avatar(): | |
| return AvatarService.build_url( | |
| style=random.choice(AvatarService.get_styles()), | |
| seed=str(random.randint(100000, 999999)), | |
| bg=random.choice(AvatarService.get_backgrounds()), | |
| ) | |