Spaces:
Sleeping
Sleeping
Update app.py (#18)
Browse files- Update app.py (4a2c65a7943d38ce6d17c9b2eaedd8c831e83e58)
495 unmodified lines49649749849950050150250350450550624 unmodified lines53153253353453553653753853954054154274 unmodified lines617618619620621622623624625495 unmodified linesreturn itemsdef _norm(self, s: str) -> str:# normalize for matching: lowercase, strip punctuation/extra spaces, unify apostrophess = s.replace("β", "'").replace("β", "'").replace("β","\"").replace("β","\"")s = s.lower()s = re.sub(r'[^a-z0-9\' ]+', ' ', s)s = re.sub(r'\s+', ' ', s).strip()return sdef _find_response_after_phrase(self, captions: list[str], phrase: str) -> str | None:24 unmodified lines# Search the quoted phrase across up to 3 adjacent cuesfor win in (1, 2, 3):for i in range(n - win):window = " ".join(norm_caps[i:i+win])if target and target in window:# scan forward up to ~10 cues for the best replybest = Nonefor j in range(i + win, min(i + win + 10, n)):raw = captions[j].strip()if not raw:continue74 unmodified lines# (B) βWhat does X say in response to the question "<quoted>β?β via captionsif "what does" in ql and " say" in ql and '"' in question or "β" in question:# pull the quoted question textqm = re.search(r'["β]([^"]+?)["β]', question)quoted = qm.group(1) if qm else ""if quoted:html_page = self._fetch_yt_html(url)495 unmodified lines49649749849950050150250350450550624 unmodified lines53153253353453553653753853954054154274 unmodified lines617618619620621622623624625495 unmodified linesreturn itemsdef _norm(self, s: str) -> str:s = s.replace("β", "'").replace("β", "'").replace("β", '"').replace("β", '"')s = s.lower()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 sdef _find_response_after_phrase(self, captions: list[str], phrase: str) -> str | None:24 unmodified lines# Search the quoted phrase across up to 3 adjacent cuesfor win in (1, 2, 3):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 replybest = Nonefor 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 captionsif ("what does" in ql and " say" in ql and (('"' in question) or ("β" in question))):# pull the quoted question textqm = re.search(r'[β"]([^ββ"]+)[β"]', question)quoted = qm.group(1) if qm else ""if quoted:html_page = self._fetch_yt_html(url)
app.py+8-8