bstraehle commited on
Commit
ad1b760
·
verified ·
1 Parent(s): e604944

Update crew.py

Browse files
Files changed (1) hide show
  1. crew.py +27 -14
crew.py CHANGED
@@ -15,10 +15,11 @@ from util import get_final_answer, get_img_b64
15
  ## LLMs
16
 
17
  MANAGER_MODEL = "gpt-4.1"
18
- AGENT_MODEL = "gpt-4.1"
19
  FINAL_ANSWER_MODEL = "gpt-4.5-preview"
20
  AUDIO_MODEL = "gpt-4o-transcribe"
21
  IMAGE_MODEL = "gpt-4.1"
 
22
 
23
  # LLM evaluation
24
 
@@ -115,23 +116,35 @@ def run_crew(question, file_path):
115
  FileNotFoundError: If the video file does not exist
116
  RuntimeError: If processing fails"""
117
  if not os.path.exists(file_path):
118
- raise FileNotFoundError(f"Image file not found: {file_path}")
119
 
120
- try:
121
- img_b64 = get_img_b64(file_path)
122
-
123
- client = OpenAI()
 
 
 
 
 
 
 
 
 
 
 
 
124
 
125
- completion = client.chat.completions.create(
126
- messages=[{"role": "user",
127
- "content": [{"type": "text", "text": question},
128
- {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{img_b64}"}}]}],
129
- model=IMAGE_MODEL
130
  )
131
-
132
- return completion.choices[0].message.content
133
  except Exception as e:
134
- raise RuntimeError(f"Failed to process image: {str(e)}")
135
 
136
  # Built-in tools
137
 
 
15
  ## LLMs
16
 
17
  MANAGER_MODEL = "gpt-4.1"
18
+ AGENT_MODEL = "gpt-4.1-mini"
19
  FINAL_ANSWER_MODEL = "gpt-4.5-preview"
20
  AUDIO_MODEL = "gpt-4o-transcribe"
21
  IMAGE_MODEL = "gpt-4.1"
22
+ VIDEO_MODEL = "gpt-4.1-mini"
23
 
24
  # LLM evaluation
25
 
 
116
  FileNotFoundError: If the video file does not exist
117
  RuntimeError: If processing fails"""
118
  if not os.path.exists(file_path):
119
+ raise FileNotFoundError(f"Video file not found: {file_path}")
120
 
121
+ try:
122
+ video = cv2.VideoCapture(file_path)
123
+
124
+ base64Frames = []
125
+
126
+ while video.isOpened():
127
+ success, frame = video.read()
128
+
129
+ if not success:
130
+ break
131
+
132
+ _, buffer = cv2.imencode(".jpg", frame)
133
+
134
+ base64Frames.append(base64.b64encode(buffer).decode("utf-8"))
135
+
136
+ video.release()
137
 
138
+ response = client.responses.create(
139
+ input=[{"role": "user",
140
+ "content": [{"type": "input_text", "text": (question)},
141
+ *[{"type": "input_image", "image_url": f"data:image/jpeg;base64,{frame}"} for frame in base64Frames]]}],
142
+ model=VIDEO_MODEL
143
  )
144
+
145
+ return response.output_text
146
  except Exception as e:
147
+ raise RuntimeError(f"Failed to process video: {str(e)}")
148
 
149
  # Built-in tools
150