Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files23 unmodified lines2425262728272829303132333435363738394041424344141 unmodified lines18618718818218919019119214 unmodified lines20720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723820423924024124264 unmodified lines30730830931031131231323 unmodified lines from smolagents import CodeAgent, DuckDuckGoSearchTool, LiteLLMModel, tool
litellm.drop_params = True raw_key = os.getenv("GEMINI_API_KEY") gemini_key = raw_key.strip(" '\"\n\r\t") if raw_key else "" env_ci = {k.upper(): v for k, v in os.environ.items() if v} raw_key = env_ci.get("GEMINI_API_KEY") or env_ci.get("GOOGLE_API_KEY") or "" gemini_key = raw_key.strip(" '\"\n\r\t") if not gemini_key: raise ValueError( "Missing GEMINI_API_KEY in environment/secrets. " "Add GEMINI_API_KEY in Space Settings -> Variables and secrets and restart the Space." ) if gemini_key.startswith("sk-or-"): raise ValueError( "GEMINI_API_KEY contains an OpenRouter key ('sk-or-...'). " "Replace it with a Google Gemini API key ('AIza...')." ) os.environ["GEMINI_API_KEY"] = gemini_key os.environ["GOOGLE_API_KEY"] = gemini_key
@tool def fetch_url_text(url: str) -> str:141 unmodified lines b64_data = base64.b64encode(f.read()).decode("utf-8")
response = litellm.completion( model="gemini/gemini-2.5-flash", model=self.model_id, api_key=gemini_key, messages=[ {14 unmodified lines except Exception as e: return f"Error inspecting image '{image_path}': {str(e)}"
candidate_models = [ "gemini/gemini-3.8-flash", "gemini/gemini-3-flash-preview", "gemini/gemini-2.5-flash-lite", "gemini/gemini-2.0-flash", ] selected_model = None last_probe_error = "" for candidate in candidate_models: try: litellm.completion( model=candidate, api_key=gemini_key, messages=[{"role": "user", "content": "Reply with OK"}], max_tokens=2048, timeout=15, ) selected_model = candidate print(f"Selected working Gemini model: {selected_model}") break except Exception as probe_exc: last_probe_error = f"{candidate}: {probe_exc}" print(f"Model probe failed for {last_probe_error}")
if not selected_model: raise RuntimeError(f"No working Gemini model found. Last error -> {last_probe_error}")
self.model_id = selected_model model = LiteLLMModel( model_id="gemini/gemini-3.8-flash", model_id=self.model_id, api_key=gemini_key, max_tokens=4096, num_retries=5,64 unmodified lines raw_text = "" if result is None else str(result).strip() return self._clean_exact_match_answer(raw_text) except Exception as exc: print(f"[AGENT ERROR] task_id={task_id}: {exc}") return f"AGENT ERROR: {exc}"
def run_and_submit_all( profile: gr.OAuthProfile | None):app.py+40-4