Download utils/message_parser.py from autonomous-media-system/ams-core-api: direct link, hf CLI and curl.
- Browser
- Download file 977 Bytes
-
https://huggingface.co/spaces/autonomous-media-system/ams-core-api/resolve/main/utils/message_parser.py
- Command line
-
hf download hf://spaces/autonomous-media-system/ams-core-api/utils/message_parser.py
-
curl -L -o message_parser.py https://huggingface.co/spaces/autonomous-media-system/ams-core-api/resolve/main/utils/message_parser.py
977 Bytes
| import re | |
| class MessageParser: | |
| # ========================= | |
| # DETECT VIDEO COUNT | |
| # ========================= | |
| def extract_video_count(self, message): | |
| numbers = re.findall(r"\d+", message) | |
| if numbers: | |
| return int(numbers[0]) | |
| text = message.lower() | |
| if "plusieurs" in text: | |
| return 5 | |
| if "beaucoup" in text: | |
| return 10 | |
| return 1 | |
| # ========================= | |
| # CLEAN THEME | |
| # ========================= | |
| def extract_theme(self, message): | |
| text = message.lower() | |
| text = re.sub(r"cree|crée", "", text) | |
| text = re.sub(r"video|vidéo|videos|vidéos", "", text) | |
| text = re.sub(r"\d+", "", text) | |
| text = text.replace("sur", "") | |
| text = text.replace("plusieurs", "") | |
| text = text.replace("explique", "") | |
| text = text.strip() | |
| text = re.sub(r"^(le|la|les|un|une|des)\s+", "", text) | |
| return text |