Download core/features.py from dmth10/tell: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/spaces/dmth10/tell/resolve/main/core/features.py
- Command line
-
hf download hf://spaces/dmth10/tell/core/features.py
-
curl -L -o features.py https://huggingface.co/spaces/dmth10/tell/resolve/main/core/features.py
1.29 kB
| """ | |
| Every TELL tool is a Feature. To add one, subclass Feature in features.py, | |
| decorate it with @register, and say which posts it wants. Nothing else changes. | |
| """ | |
| from .post import Post | |
| class Feature: | |
| name = "Feature" | |
| description = "" | |
| kinds: set[str] = set() # post kinds this looks at (empty = any kind) | |
| needs_text = False # only run if there's readable text | |
| ready = True # False = placeholder, shows as "coming soon" | |
| def wants(self, post: Post) -> bool: | |
| if self.kinds and post.kind not in self.kinds: | |
| return False | |
| if self.needs_text and not post.all_text: | |
| return False | |
| # a feature with no rules at all would grab every post, which is never what you want | |
| return bool(self.kinds or self.needs_text) | |
| def run(self, post: Post, options: dict) -> dict: | |
| raise NotImplementedError(f"{self.name} has no run() yet") | |
| _registry: list[Feature] = [] | |
| def register(cls): | |
| if any(type(f) is cls for f in _registry): | |
| return cls # module got imported twice, don't double up | |
| _registry.append(cls()) | |
| return cls | |
| def all_features() -> list[Feature]: | |
| return list(_registry) | |
| def pick(post: Post) -> list[Feature]: | |
| return [f for f in _registry if f.wants(post)] | |