Spaces:
Build error
Build error
Download roop/template_parser.py from Letcool/Roop_unleashed: direct link, hf CLI and curl.
- Browser
- Download file 658 Bytes
-
https://huggingface.co/spaces/Letcool/Roop_unleashed/resolve/main/roop/template_parser.py
- Command line
-
hf download hf://spaces/Letcool/Roop_unleashed/roop/template_parser.py
-
curl -L -o template_parser.py https://huggingface.co/spaces/Letcool/Roop_unleashed/resolve/main/roop/template_parser.py
658 Bytes
| import re | |
| from datetime import datetime | |
| template_functions = { | |
| "timestamp": lambda data: str(int(datetime.now().timestamp())), | |
| "i": lambda data: data.get("index", False), | |
| "file": lambda data: data.get("file", False), | |
| "date": lambda data: datetime.now().strftime("%Y-%m-%d"), | |
| "time": lambda data: datetime.now().strftime("%H-%M-%S"), | |
| } | |
| def parse(text: str, data: dict): | |
| pattern = r"\{([^}]+)\}" | |
| matches = re.findall(pattern, text) | |
| for match in matches: | |
| replacement = template_functions[match](data) | |
| if replacement is not False: | |
| text = text.replace(f"{{{match}}}", replacement) | |
| return text | |