Spaces:
Build error
Build error
Download audio.py from mludvig/agents-course-final: direct link, hf CLI and curl.
- Browser
- Download file 993 Bytes
-
https://huggingface.co/spaces/mludvig/agents-course-final/resolve/main/audio.py
- Command line
-
hf download hf://spaces/mludvig/agents-course-final/audio.py
-
curl -L -o audio.py https://huggingface.co/spaces/mludvig/agents-course-final/resolve/main/audio.py
993 Bytes
| from langchain_core.messages import SystemMessage, HumanMessage | |
| from langchain_openai import ChatOpenAI | |
| def audio_transcript_tool(base64_audio: str) -> str: | |
| """ | |
| Get a transcript of an audio file. | |
| Args: | |
| base64_audio (str): Base64 encoded audio file. | |
| Returns: | |
| str: The transcript of the audio file. | |
| """ | |
| print(f"audio_transcript_tool called: {base64_audio[:50]}...") | |
| system_message = SystemMessage(content="Transcribe the provided audio file and return the transcribed text only.") | |
| audio_message = HumanMessage(content=[{ | |
| "type": "input_audio", | |
| "input_audio": { | |
| "data": base64_audio, | |
| "format": "mp3", | |
| } | |
| }]) | |
| messages = [system_message, audio_message] | |
| # Get the response from the LLM | |
| llm = ChatOpenAI(model="gpt-4o-mini-audio-preview") | |
| response = llm.invoke(messages) | |
| answer = response.content | |
| print(f"audio_transcript_tool response: {answer}") | |
| return answer | |