Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files1267 unmodified lines126812691270127112721273127412 unmodified lines128712881289129012911292129329 unmodified lines132313241325132613271328132913301331133211 unmodified lines13441345134613471348134913509 unmodified lines136013611362136313641359136013651366136713681369137013711149 unmodified lines252125222523251625242525252612 unmodified lines253925402541253525422543254425452546254725482540254925502542254325442551255225532554255525562557255825592560256125622563256425652566255125672568256925702571257225732574257525762577257825792580258125822583258425852586258725881267 unmodified lines )
video_analyzed = False video_analysis_error = "" gemini_pool = self.provider_key_pools.get("gemini") or [] if gemini_pool and needs_video_analysis: gemini_models = list(12 unmodified lines while True: g_key = self._get_api_key(g_model) if not g_key: video_analysis_error = "no gemini api key" break try: gm_resp = requests.post(29 unmodified lines sections.append(f"Multimodal Video Analysis:\n{analysis_text}") video_analyzed = True break video_analysis_error = "gemini returned empty candidate" break err_low = gm_resp.text.lower() video_analysis_error = f"gemini status {gm_resp.status_code}: {gm_resp.text[:200]}" if gm_resp.status_code in (401, 402, 403): if hasattr(self, "_rotate_api_key") and self._rotate_api_key( "gemini", permanent=True11 unmodified lines except Exception as gm_exc: if "task time budget exhausted" in str(gm_exc).lower(): raise video_analysis_error = f"gemini exception: {type(gm_exc).__name__}: {gm_exc}" break if video_analyzed: break9 unmodified lines break
if not has_transcript and not video_analyzed: reason = f" ({video_analysis_error})" if video_analysis_error else "" sections.append( "Transcript/Video Analysis Status: unavailable. " "Use web_search or search_wikipedia with the video title, channel, or quoted dialogue." "Transcript/Video Analysis Status: unavailable" f"{reason}. " "Use web_search or search_wikipedia with the video title, channel, or quoted dialogue. " "Do NOT guess visual counts from the question alone." )
return _trim_tool_output("\n\n".join(sections), max_chars=12000)1149 unmodified lines # Usuwanie znaczników cleaned = re.sub(r"</?code[^>]*>", "", cleaned, flags=re.IGNORECASE) cleaned = re.sub(r"final_answer\s*\(\s*", "", cleaned, flags=re.IGNORECASE) cleaned = re.sub(r"\)\s*$", "", cleaned) cleaned = re.sub(r"^final_answer\s*:\s*", "", cleaned, flags=re.IGNORECASE) cleaned = cleaned.strip()
12 unmodified lines cleaned = re.sub(r"(?im)^\s*(?:#\s*)?(?:thought|reasoning|plan)\s*:.*$", "", cleaned).strip()
fa_call = re.search( r"final_answer\(\s*(?:answer\s*=\s*)?(['\"])(.*?)\1\s*\)", r"final_answer\s*\(\s*(?:answer\s*=\s*)?" r"(?:(['\"])(.*?)\1|([^()]*?))" r"\s*\)", cleaned, flags=re.DOTALL, ) if fa_call: cleaned = fa_call.group(2).strip() cleaned = (fa_call.group(2) or fa_call.group(3) or "").strip(
if "->" in cleaned: tail_part = cleaned.split("->")[-1].strip() quoted_match = re.findall(r'""([^"]+)""|"([^"]+)"', tail_part) # Obsługa formatu "answer -> wartość" (tylko gdy -> jest w kontekście odpowiedzi) arrow_match = re.search( r"\b(?:answer|result|output|final\s+answer)\s*->\s*(.+)$", cleaned, flags=re.IGNORECASE | re.DOTALL, ) if arrow_match: tail_part = arrow_match.group(1).strip() # Najpierw spróbuj wyciągnąć ostatni fragment w cudzysłowach (pojedynczych lub podwójnych) quoted_match = re.findall(r'"([^"]+)"|\'([^\']+)\'', tail_part) if quoted_match: last_q = quoted_match[-1] cleaned = (last_q[0] or last_q[1]).strip() else: cleaned = tail_part.strip(" .\"'")
lines = [ln.strip(" \t\r\n-*•\"'") for ln in cleaned.splitlines() if ln.strip()] junk_pattern = re.compile( r"^(?:the wikipedia article|the youtube video|the search results show|this scene is from|" r"the page is quite long|the task doesn't have|the download failed|let me try|let me search|" r"let me check|now i need to find|i found the|the operation is not commutative|" r"the scene occurs|so the answer is|therefore|thus|hence|in conclusion|" r"i need to|i should|i will|i can|based on the|according to the)\b", re.IGNORECASE, ) answer_line = "" for ln in reversed(lines): if not junk_pattern.match(ln): answer_line = ln break if not answer_line: return "" cleaned = answer_line if not lines: return "" cleaned = lines[-1]app.py+43-9