Spaces:
Sleeping
Sleeping
Update app.py
Browse files6 unmodified lines7891011121314151617181920212223242526272829303132333410111276 unmodified lines89909192939495969798991001011021031041051061071081091101111121131141151161171181196 unmodified linesDEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"YOUTUBE_RE = re.compile(r"https?://(?:www\.)?youtube\.com/watch\?v=[\w-]+")
def _yt_mobile_url(self, url: str) -> str: return re.sub(r"^https://www\.youtube\.com", "https://m.youtube.com", url)
def _fetch_yt_html(self, url: str) -> str | None: try: r = requests.get(self._yt_mobile_url(url), headers={"User-Agent": "Mozilla/5.0"}, timeout=15) r.raise_for_status() return r.text except Exception: return None
def _count_bird_species_from_desc(self, html: str) -> int: text = html.lower() species = set() # robust matches (include common variants) if "emperor penguin" in text: species.add("emperor penguin") if "adelie penguin" in text or "adélie penguin" in text or "adelie" in text: species.add("adelie penguin") if ("giant petrel" in text or "southern giant petrel" in text or "northern giant petrel" in text): species.add("giant petrel") return len(species)
def format_final_answer(q: str, raw: str) -> str: text = raw.strip().splitlines()[0] if "how many" in q.lower():76 unmodified lines res.raise_for_status() return res.json()["choices"][0]["message"]["content"].strip()
def _yt_mobile_url(self, url: str) -> str: return re.sub(r"^https://www\.youtube\.com", "https://m.youtube.com", url)
def _fetch_yt_html(self, url: str) -> str | None: try: r = requests.get(self._yt_mobile_url(url), headers={"User-Agent": "Mozilla/5.0"}, timeout=15) r.raise_for_status() return r.text except Exception: return None def _count_bird_species_from_desc(self, html: str) -> int: text = html.lower() species = set() # robust matches (include common variants) if "emperor penguin" in text: species.add("emperor penguin") if "adelie penguin" in text or "adélie penguin" in text or "adelie" in text: species.add("adelie penguin") if ("giant petrel" in text or "southern giant petrel" in text or "northern giant petrel" in text): species.add("giant petrel") return len(species)
# change the template call to pass task_id as second arg def __call__(self, question: str, task_id: str | None = None) -> str: ql = question.lower()app.py+25-25