Spaces:
Running on Zero
Running on Zero
Download timeline_intent.py from fffiloni/fastframes-voice: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/fffiloni/fastframes-voice/resolve/main/timeline_intent.py
- Command line
-
hf download hf://spaces/fffiloni/fastframes-voice/timeline_intent.py
-
curl -L -o timeline_intent.py https://huggingface.co/spaces/fffiloni/fastframes-voice/resolve/main/timeline_intent.py
1.27 kB
| """Recognize explicit edit requests for a numbered or older segment.""" | |
| import re | |
| import unicodedata | |
| EDIT = r"\b(?:refais|refaire|refilme|corrige|modifie|retouche|reprends|remplace|redo|re-?shoot|edit|replace|change|regenerate|remake)\s+" | |
| ARTICLE = r"(?:(?:moi|le|la|les|the|my|mon|ce|l)\s+)*" | |
| CLIP = r"(?:segments?|portions?|clips?|plans?|shots?)" | |
| ORDINALS = {"first":1,"premier":1,"premiere":1,"second":2,"seconde":2,"deuxieme":2,"third":3,"troisieme":3} | |
| LABEL = "|".join(ORDINALS) | |
| TARGET = re.compile(EDIT + ARTICLE + rf"(?:(?:{CLIP}\s+(?:(?:numero|number|no)\s*)?#?\s*(?P<index>\d+))|" | |
| rf"(?P<ordinal>{LABEL}|\d+(?:st|nd|rd|th|e|eme))\s+{CLIP}|" | |
| rf"(?P<older>avant[- ]dernier[e]?|penultimate|second[- ]to[- ]last)\s+{CLIP})\b") | |
| def explicit_target(text, latest): | |
| normalized = unicodedata.normalize("NFKD",text.lower()).encode("ascii","ignore").decode().replace("'"," ") | |
| normalized = normalized.replace("lavant","l avant") | |
| match = TARGET.search(normalized) | |
| if not match: | |
| return None | |
| if match["older"]: | |
| return latest-1 | |
| if match["index"]: | |
| return int(match["index"]) | |
| word = match["ordinal"] | |
| return ORDINALS[word] if word in ORDINALS else int(re.match(r"\d+",word)[0]) | |