Spaces:
Sleeping
Sleeping
Update app.py
#18
by olcapone - opened
495 unmodified lines49649749849950049950050250350150250350450550624 unmodified lines53153253353453453553653753853953954054154274 unmodified lines617618619620620621622622623624625495 unmodified lines return items
def _norm(self, s: str) -> str: # normalize for matching: lowercase, strip punctuation/extra spaces, unify apostrophes s = s.replace("’", "'").replace("‘", "'").replace("“","\"").replace("”","\"") s = s.replace("’", "'").replace("‘", "'").replace("“", '"').replace("”", '"') s = s.lower() s = re.sub(r'[^a-z0-9\' ]+', ' ', s) s = re.sub(r'\s+', ' ', s).strip() s = re.sub(r"[^a-z0-9' ]+", " ", s) s = s.replace("'", "") # <-- NEW: drop apostrophes to match ASR "isn t" s = re.sub(r"\s+", " ", s).strip() return s
def _find_response_after_phrase(self, captions: list[str], phrase: str) -> str | None:24 unmodified lines # Search the quoted phrase across up to 3 adjacent cues for win in (1, 2, 3): for i in range(n - win): for i in range(n - win + 1): window = " ".join(norm_caps[i:i+win]) if target and target in window: # scan forward up to ~10 cues for the best reply best = None for j in range(i + win, min(i + win + 10, n)): for j in range(i + win, min(i + win + 12, n)): raw = captions[j].strip() if not raw: continue74 unmodified lines
# (B) “What does X say in response to the question "<quoted>”?” via captions if "what does" in ql and " say" in ql and '"' in question or "“" in question: if ("what does" in ql and " say" in ql and (('"' in question) or ("“" in question))): # pull the quoted question text qm = re.search(r'["“]([^"]+?)["”]', question) qm = re.search(r'[“"]([^“”"]+)[”"]', question) quoted = qm.group(1) if qm else "" if quoted: html_page = self._fetch_yt_html(url)app.py+8-8