Модель Олламы возвращает пустую строку ollama.generate()Python

Программы на Python
Ответить
Anonymous
 Модель Олламы возвращает пустую строку ollama.generate()

Сообщение Anonymous »

Я столкнулся с этой проблемой в pyhon при использовании Moondream:latest при импорте ollama.

Модель устанавливается, когда я запускаю этот метод.
По какой-то причине выходные данные представляют собой пустую строку, любая помощь будет полезна
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📹 Camera stream active. Press SPACE to capture, ESC to cancel.")

# 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("🚫 Camera cancelled.")
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🤔 Model analyzing...")

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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»