Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files268 unmodified lines26927027127227227327427530 unmodified lines3063073083093093103113123131205 unmodified lines1519152015211521152215231524152586 unmodified lines161216131614161416151615161616171617161816191620161816191620162116221623162416251626162716281629163016311632163349 unmodified lines1683168416851686168716881676168916901691169260 unmodified lines175317541755175617571758175926 unmodified lines1786178717881775178917901791179217931794179568 unmodified lines1864186518661867186818691870187118721873268 unmodified lines
def _read_single(path: str, max_chars: int) -> str: f_ext = os.path.splitext(path)[1].lower() if f_ext in {".xlsx", ".xls"}: if f_ext in {".xlsx", ".xlsm", ".xls"}: sheets = pd.read_excel(path, sheet_name=None) if not sheets: return "Empty Excel workbook."30 unmodified lines if not os.path.isfile(file_path): return f"File not found: '{file_path}'" ext = os.path.splitext(file_path)[1].lower() if ext == ".zip" or zipfile.is_zipfile(file_path): excel_exts = {".xlsx", ".xlsm", ".xls"} if ext == ".zip" or (ext not in excel_exts and zipfile.is_zipfile(file_path)): extract_dir = os.path.join( os.path.dirname(file_path), f"extracted_{os.path.basename(file_path)}",1205 unmodified lines os.environ["OPENROUTER_API_KEY"] = key elif model_name.startswith("groq/"): os.environ["GROQ_API_KEY"] = key kwargs.setdefault("timeout", 45) kwargs.setdefault("timeout", getattr(self, "timeout", None) or 45) if model_name.startswith("openrouter/"): kwargs["max_tokens"] = 4096 return kwargs86 unmodified lines except Exception: return (model_name, True)
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor, wait as futures_wait
probed_slice = self.working_models[:5] with ThreadPoolExecutor(max_workers=5) as probe_pool: probe_results = dict( probe_pool.map(lambda m: _probe_candidate(m), probed_slice, timeout=6) ) probe_results = {} probe_pool = ThreadPoolExecutor(max_workers=5) try: probe_futures = [probe_pool.submit(_probe_candidate, m) for m in probed_slice] done, _ = futures_wait(probe_futures, timeout=12) for fut in done: try: probed_name, probed_ok = fut.result() probe_results[probed_name] = probed_ok except Exception: pass finally: probe_pool.shutdown(wait=False, cancel_futures=True) filtered_models = [m for m in self.working_models if probe_results.get(m, True)] if filtered_models: self.working_models = filtered_models49 unmodified lines "max_steps": 10, "verbosity_level": 0, } from smolagents import MultiStepAgent accepted_params = set(sig.parameters) | set(inspect.signature(MultiStepAgent.__init__).parameters) filtered_agent_kwargs = {k: v for k, v in agent_kwargs.items() if k in sig.parameters} filtered_agent_kwargs = {k: v for k, v in agent_kwargs.items() if k in accepted_params} self.agent = CodeAgent(**filtered_agent_kwargs)
if not hasattr(self, "_build_model") or not hasattr(self, "agent"):60 unmodified lines self.agent.max_steps = min(int(prev_max_steps), 4)
try: backoff_rounds = 0 while time.monotonic() < deadline: rate_limited_models = set() rate_limited_providers = set()26 unmodified lines built_model.timeout = call_timeout self.agent.model = built_model result = self.agent.run(prompt) cleaned = self._clean_exact_match_answer("" if result is None else str(result).strip()) raw_result = "" if result is None else str(result).strip() if raw_result.lower().startswith("error in generating"): raise RuntimeError(raw_result) cleaned = self._clean_exact_match_answer(raw_result) if cleaned and not cleaned.startswith("AGENT ERROR:"): return cleaned blocked_models.add(model_name)68 unmodified lines if self._rotate_api_key(prov): rotated_any = True if not rotated_any: if rate_limited_models and backoff_rounds < 3 and (deadline - time.monotonic()) > 15.0: backoff_rounds += 1 time.sleep(4.0 * backoff_rounds) continue break finally: if prev_max_steps is not None:app.py+32-11