olcapone commited on
Commit
e8c6710
·
verified ·
1 Parent(s): ff20172

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -125,6 +125,10 @@ class BasicAgent:
125
  def _yt_mobile_url(self, url: str) -> str:
126
  return re.sub(r"^https://www\.youtube\.com", "https://m.youtube.com", url)
127
 
 
 
 
 
128
  def _fetch_yt_html(self, url: str) -> str | None:
129
  try:
130
  r = requests.get(self._yt_mobile_url(url),
@@ -162,12 +166,19 @@ class BasicAgent:
162
  return str(n) # EXACT MATCH wants bare number
163
  # Deterministic LLM fallback constrained to description only
164
  yt_sys = (
165
- "Answer with ONLY the final number. Use only the official video description text. "
166
- "Count distinct bird species explicitly mentioned (e.g., Emperor penguin, Adélie penguin, Giant petrel)."
167
  )
168
  raw = self._llm(f"{yt_sys}\n\nQuestion: {question}")
169
- return format_final_answer(question, raw)
 
 
 
 
 
170
 
 
 
171
 
172
  # 1) quick math
173
  calc = self._maybe_calc(question)
 
125
  def _yt_mobile_url(self, url: str) -> str:
126
  return re.sub(r"^https://www\.youtube\.com", "https://m.youtube.com", url)
127
 
128
+ def _extract_video_id(url: str) -> str | None:
129
+ m = re.search(r"[?&]v=([\w-]{6,})", url)
130
+ return m.group(1) if m else None
131
+
132
  def _fetch_yt_html(self, url: str) -> str | None:
133
  try:
134
  r = requests.get(self._yt_mobile_url(url),
 
166
  return str(n) # EXACT MATCH wants bare number
167
  # Deterministic LLM fallback constrained to description only
168
  yt_sys = (
169
+ "Return ONLY the number (digits only, no words, no punctuation). "
170
+ "Count the distinct bird species explicitly mentioned in the official video description (e.g., Emperor penguin, Adélie penguin, Giant petrel)."
171
  )
172
  raw = self._llm(f"{yt_sys}\n\nQuestion: {question}")
173
+ num = _extract_bare_number(raw)
174
+
175
+ if num is None:
176
+ # second attempt: ultra-strict
177
+ raw2 = self._llm("Output only a single integer with no other text.\n" + question)
178
+ num = _extract_bare_number(raw2)
179
 
180
+ if num is not None:
181
+ return num
182
 
183
  # 1) quick math
184
  calc = self._maybe_calc(question)