bstraehle commited on
Commit
2483171
·
verified ·
1 Parent(s): d8cd338

Update crew.py

Browse files
Files changed (1) hide show
  1. crew.py +36 -6
crew.py CHANGED
@@ -38,18 +38,18 @@ def run_crew(question, file_path):
38
 
39
  @tool("Audio Analysis Tool")
40
  def audio_analysis_tool(question: str, file_path: str) -> str:
41
- """Transcribe the audio file and answer the question.
42
 
43
  Args:
44
  question (str): Question about the audio file
45
- file_path (str): Path of audio the file
46
 
47
  Returns:
48
  str: Answer to the question about the audio file
49
 
50
  Raises:
51
- FileNotFoundError: If audio file does not exist
52
- RuntimeError: If transcription fails"""
53
  if not os.path.exists(file_path):
54
  raise FileNotFoundError(f"Audio file not found: {file_path}")
55
 
@@ -64,11 +64,41 @@ def run_crew(question, file_path):
64
 
65
  return transcript.text
66
  except Exception as e:
67
- raise RuntimeError(f"Failed to transcribe audio: {str(e)}")
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  # Built-in tools
70
 
71
- image_analysis_tool = VisionTool()
72
  python_coding_tool = CodeInterpreterTool()
73
  video_analysis_tool = YoutubeVideoSearchTool()
74
  web_search_tool = SerperDevTool()
 
38
 
39
  @tool("Audio Analysis Tool")
40
  def audio_analysis_tool(question: str, file_path: str) -> str:
41
+ """Answer a question about an audio file.
42
 
43
  Args:
44
  question (str): Question about the audio file
45
+ file_path (str): Path of the audio file
46
 
47
  Returns:
48
  str: Answer to the question about the audio file
49
 
50
  Raises:
51
+ FileNotFoundError: If the audio file does not exist
52
+ RuntimeError: If processing fails"""
53
  if not os.path.exists(file_path):
54
  raise FileNotFoundError(f"Audio file not found: {file_path}")
55
 
 
64
 
65
  return transcript.text
66
  except Exception as e:
67
+ raise RuntimeError(f"Failed to process audio: {str(e)}")
68
 
69
+ @tool("Image Analysis Tool")
70
+ def image_analysis_tool(question: str, file_path: str) -> str:
71
+ """Answer a question about an image file.
72
+
73
+ Args:
74
+ question (str): Question about the image file
75
+ file_path (str): Path of the image file
76
+
77
+ Returns:
78
+ str: Answer to the question about the image file
79
+
80
+ Raises:
81
+ FileNotFoundError: If the image file does not exist
82
+ RuntimeError: If processing fails"""
83
+ if not os.path.exists(file_path):
84
+ raise FileNotFoundError(f"Image file not found: {file_path}")
85
+
86
+ try:
87
+ client = OpenAI()
88
+
89
+ transcript = client.audio.transcriptions.create(
90
+ file=open(file_path, "rb"),
91
+ model=STT_MODEL,
92
+ prompt=question
93
+ )
94
+
95
+ return transcript.text
96
+ except Exception as e:
97
+ raise RuntimeError(f"Failed to process image: {str(e)}")
98
+
99
  # Built-in tools
100
 
101
+ #image_analysis_tool = VisionTool()
102
  python_coding_tool = CodeInterpreterTool()
103
  video_analysis_tool = YoutubeVideoSearchTool()
104
  web_search_tool = SerperDevTool()