Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files291 unmodified lines292293294295296297298299300301302303304305306307308309310311312313314315316317318295319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359296297298291 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=self.model_id, api_key=gemini_key, max_tokens=4096, num_retries=5, timeout=45, )
exact_match_rule = ( "CRITICAL OUTPUT RULES FOR EXACT MATCH EVALUATION:\n" "- Always write valid Python code inside ```py and ``` fences. NEVER put 'Thought:' or HTML tags like <code> inside the Python block.\n" "- Never call built-in open(); use read_local_file(file_path) for text/spreadsheet files, " "inspect_image(image_path, question) for images, and transcribe_audio(audio_path, question) for audio files (.mp3, .wav).\n" "- If web_search returns no results, use search_wikipedia(query) or fetch_url_text(url).\n" "- Return ONLY the concise exact answer value itself " "(e.g. a number, date, name, or short phrase) via final_answer().\n" "- NEVER include introductory text, explanations, markdown formatting, or the phrase 'FINAL ANSWER'.\n" "- Do not wrap the answer in a dictionary like {'answer': ...}; pass the plain answer string directly." )
self.agent = CodeAgent( model=model, tools=[ web_search, search_wikipedia, fetch_url_text, download_task_file, read_local_file, inspect_image, transcribe_audio, ], instructions=exact_match_rule, max_steps=10, verbosity_level=1, ) print("CodeAgent initialized with LiteLLMModel.")
@tool def transcribe_audio( audio_path: str,app.py+1-65