Spaces:
Build error
Build error
Update langgraph_agent.py
Browse files158 unmodified lines1591601611621631641651661671681691701711721731741751761771781791801817 unmodified lines18919019119219319419526 unmodified lines222223224225226227228229158 unmodified linesexcept Exception as e:return {"error": f"Error describing image {image_path}: {str(e)}"}@tooldef transcribe_audio(audio_path: str) -> Dict[str, str]:"""Transcribes an audio file (e.g., MP3) to text using an automatic speech recognition modelfrom the Hugging Face Inference API. Requires HF_API_TOKEN environment variable to be set."""if not HF_INFERENCE_CLIENT:return {"error": "Hugging Face API token not configured for audio transcription. Cannot use this tool."}try:with open(audio_path, "rb") as f:audio_bytes = f.read()transcription = HF_INFERENCE_CLIENT.automatic_speech_recognition(audio_bytes)return {"audio_transcription": transcription, "audio_path": audio_path}except FileNotFoundError:return {"error": f"Audio file not found: {audio_path}. Please ensure the file exists."}except Exception as e:return {"error": f"Error transcribing audio {audio_path}: {str(e)}"}API_KEY = os.getenv("GEMINI_API_KEY")7 unmodified linesread_file_content,python_interpreter,describe_image,transcribe_audio,]26 unmodified linesllm_with_tools = llm.bind_tools(tools)def assistant(state: MessagesState):messages_to_send = [sys_msg] + state["messages"]return {"messages": [llm_with_tools.invoke(messages_to_send)]}builder = StateGraph(MessagesState)builder.add_node("assistant", assistant)158 unmodified lines1591601611621631647 unmodified lines17217317417517617726 unmodified lines204205206207208209210211212213158 unmodified linesexcept Exception as e:return {"error": f"Error describing image {image_path}: {str(e)}"}API_KEY = os.getenv("GEMINI_API_KEY")7 unmodified linesread_file_content,python_interpreter,describe_image,]26 unmodified linesllm_with_tools = llm.bind_tools(tools)def assistant(state: MessagesState):messages_to_send = [sys_msg] + state["messages"]llm_response = llm_with_tools.invoke(messages_to_send)print(f"LLM Raw Response: {llm_response}") # Add this linereturn {"messages": [llm_response]}builder = StateGraph(MessagesState)builder.add_node("assistant", assistant)
langgraph_agent.py+4-20