JabrilJacobs commited on
Commit
89fade4
·
verified ·
1 Parent(s): 4e87a06

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +14 -1
tools.py CHANGED
@@ -11,6 +11,7 @@ import requests
11
  import os
12
  import subprocess
13
  import tempfile
 
14
 
15
  def download_file(task_id: str, file_name: str) -> str:
16
  """Downloads a file associated with a task_id and returns the local file path"""
@@ -181,4 +182,16 @@ def execute_python_code(file_path: str, timeout: int = 60) -> str:
181
  except subprocess.TimeoutExpired:
182
  return "Error: Code execution timed out"
183
  except Exception as e:
184
- return f"Error executing code: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  import os
12
  import subprocess
13
  import tempfile
14
+ import openai
15
 
16
  def download_file(task_id: str, file_name: str) -> str:
17
  """Downloads a file associated with a task_id and returns the local file path"""
 
182
  except subprocess.TimeoutExpired:
183
  return "Error: Code execution timed out"
184
  except Exception as e:
185
+ return f"Error executing code: {str(e)}"
186
+
187
+ def transcribe_audio(file_path: str) -> str:
188
+ """Transcribe audio file using OpenAI Whisper"""
189
+ try:
190
+ with open(file_path, "rb") as audio_file:
191
+ transcript = openai.audio.transcriptions.create(
192
+ model="whisper-1",
193
+ file=audio_file
194
+ )
195
+ return transcript.text
196
+ except Exception as e:
197
+ return f"Error transcribing audio: {str(e)}"