SergeyO7 commited on
Commit
de0487a
·
verified ·
1 Parent(s): 98eeb83

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +17 -12
agent.py CHANGED
@@ -162,20 +162,25 @@ class DownloadTaskAttachmentTool(Tool):
162
  except requests.exceptions.RequestException as e:
163
  return f"Error downloading file for task {task_id}: {str(e)}"
164
 
165
- @tool
166
- def SpeechToTextTool(audio_path: str) -> str:
167
- """Tool for converting an audio file to text using OpenAI Whisper.
168
- Args:
169
- audio_path (str): Path to audio file
170
- Returns:
171
- str: audio speech text
172
- """
173
- model = whisper.load_model("base")
 
 
 
 
174
 
175
- if not os.path.exists(audio_path):
 
176
  return f"Error: File not found at {audio_path}"
177
- result = model.transcribe(audio_path)
178
- return result.get("text", "")
179
 
180
  class ExcelReaderTool(Tool):
181
  name = "excel_reader"
 
162
  except requests.exceptions.RequestException as e:
163
  return f"Error downloading file for task {task_id}: {str(e)}"
164
 
165
+ class SpeechToTextTool(Tool):
166
+ name = "speech_to_text"
167
+ description = (
168
+ "Converts an audio file to text using OpenAI Whisper."
169
+ )
170
+ inputs = {
171
+ "audio_path": {"type": "string", "description": "Path to audio file (.mp3, .wav)"},
172
+ }
173
+ output_type = "string"
174
+
175
+ def __init__(self):
176
+ super().__init__()
177
+ self.model = whisper.load_model("base")
178
 
179
+ def forward(self, audio_path: str) -> str:
180
+ if not os.path.exists(audio_path):
181
  return f"Error: File not found at {audio_path}"
182
+ result = self.model.transcribe(audio_path)
183
+ return result.get("text", "")
184
 
185
  class ExcelReaderTool(Tool):
186
  name = "excel_reader"