Spaces:
Build error
Build error
Update langgraph_agent.py
Browse files91 unmodified lines9293949595969797989910010110210310410510610710810911010211111211311411511611711811912011011111211311411512112211712312412512612712812913013113213391 unmodified lineselse: print("WARNING: HF_API_TOKEN not set. If any other HF tools are used, they might not function.")
@tool@tooldefdef read_file_content(file_path: str) -> Dict[str, str]: """Reads the content of a file and returns its primary information. For text/code/excel, returns content. For media, returns a prompt to use specific tools.""" """Reads the content of a file and returns its primary information. For text/code/excel, returns content. For media, indicates it's a blob for LLM processing.""" try: _, file_extension = os.path.splitext(file_path) file_extension = file_extension.lower()
# Prioritize handling of video, audio, and image files for direct LLM processing if file_extension in (".mp4", ".avi", ".mov", ".mkv", ".webm"): return {"file_type": "video", "file_name": file_path, "file_content": f"Video file '{file_path}' detected. The LLM (Gemini 2.5 Pro) can process this video content directly as a blob."} elif file_extension == ".mp3": return {"file_type": "audio", "file_name": file_path, "file_content": f"Audio file '{file_path}' detected. The LLM (Gemini 2.5 Pro) can process this audio content directly as a blob."} elif file_extension in (".jpeg", ".jpg", ".png"): return {"file_type": "image", "file_name": file_path, "file_content": f"Image file '{file_path}' detected. The LLM (Gemini 2.5 Pro) can process this image content directly as a blob."} # Handle text and code files if file_extension in (".txt", ".py"): elif file_extension in (".txt", ".py"): with open(file_path, "r", encoding="utf-8") as f: content = f.read() return {"file_type": "text/code", "file_name": file_path, "file_content": content} # Handle Excel files elif file_extension == ".xlsx": df = pd.read_excel(file_path) content = df.to_string() return {"file_type": "excel", "file_name": file_path, "file_content": content} elif file_extension in (".jpeg", ".jpg", ".png"): # For images, we indicate it's an image file and expect the LLM to handle the blob directly. return {"file_type": "image", "file_name": file_path, "file_content": f"Image file '{file_path}' detected. The LLM (Gemini 2.5 Pro) can process this image content directly."} elif file_extension == ".mp3": # For MP3, we indicate it's an audio file and expect the LLM to handle the blob directly. return {"file_type": "audio", "file_name": file_path, "file_content": f"Audio file '{file_path}' detected. The LLM (Gemini 2.5 Pro) can process this audio content directly."} else: return {"file_type": "unsupported", "file_name": file_path, "file_content": f"Unsupported file type: {file_extension}. Only .txt, .py, .xlsx, .jpeg, .jpg, .png, .mp3 files are recognized."} return {"file_type": "unsupported", "file_name": file_path, "file_content": f"Unsupported file type: {file_extension}. Only .txt, .py, .xlsx, .jpeg, .jpg, .png, .mp3, .mp4, .avi, .mov, .mkv, .webm files are recognized."} except FileNotFoundError: return {"file_error": f"File not found: {file_path}. Please ensure the file exists in the environment."} except Exception as e: return {"file_error": f"Error reading file {file_path}: {e}"}
@tooldef python_interpreter(code: str) -> Dict[str, str]: """Executes Python code and returns its standard output. If there's an error during execution, it returns the error message."""langgraph_agent.py+18-10