Модель устанавливается, когда я запускаю этот метод.
По какой-то причине выходные данные представляют собой пустую строку, любая помощь будет полезна
def capture_describe(self, user_input: str) -> str | None:
"""
Displays live video feed and analyzes a frame with the vision model.
User presses SPACE to capture the current frame for analysis.
Args:
user_input (str): Context/prompt for the vision model.
Returns:
str | None: The generated description of the image.
"""
captured_frame = None
if not self.cap.isOpened():
return None
print("\n
# Display live feed and wait for capture
while captured_frame is None:
ret, frame = self.cap.read()
if not ret:
return None
# Display frame with instructions overlay
display_frame = frame.copy()
cv2.putText(display_frame, "Press SPACE to capture | ESC to cancel",
(10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
cv2.imshow(self.window_name, display_frame)
# Wait for key (1ms timeout for responsive display)
key = cv2.waitKey(1) & 0xFF
if key == 32: # SPACE key
captured_frame = frame
print("✓ Frame captured. Analyzing...")
elif key == 27: # ESC key
print("
cv2.destroyWindow(self.window_name)
return None
# Close the live feed window
cv2.destroyWindow(self.window_name)
# Convert to RGB for processing
image = Image.fromarray(cv2.cvtColor(captured_frame, cv2.COLOR_BGR2RGB))
# Prepare image as bytes for Ollama
img_bytes = io.BytesIO()
image.save(img_bytes, format='PNG')
img_bytes.seek(0)
image_base64 = base64.b64encode(img_bytes.read()).decode("utf-8")
try:
full_response = ""
print("\n
response = ollama.generate(
model=self.model,
prompt=f"{self.prompt}. User:{user_input}",
images=[image_base64],
stream=False
)
full_response = response.get('response',)
return full_response
except Exception as e:
print(f"Error querying vision model: {e}")
return None
Мобильная версия