Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions vllm_omni/entrypoints/openai/serving_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import TYPE_CHECKING, Any, Final, Optional, cast

import jinja2
import numpy as np
import torch
from fastapi import Request
from PIL import Image
Expand Down Expand Up @@ -1829,8 +1830,6 @@ def _create_image_choice(
if isinstance(image_data, Image.Image):
images.append(image_data)
elif hasattr(image_data, "cpu"): # Tensor
import numpy as np

# Convert tensor to PIL Image
img_array = image_data.float().detach().cpu().numpy()
# Handle different tensor formats (CHW -> HWC)
Expand All @@ -1857,6 +1856,8 @@ def _create_image_choice(
image_contents = []
for img in images:
with BytesIO() as buffer:
if isinstance(img, np.ndarray):
img = Image.fromarray(img)
img.save(buffer, format="PNG")
img_bytes = buffer.getvalue()
img_base64 = base64.b64encode(img_bytes).decode("utf-8")
Expand Down Expand Up @@ -2089,6 +2090,8 @@ async def _create_diffusion_chat_completion(
image_contents: list[dict[str, Any]] = []
for img in images:
with BytesIO() as buffer:
if isinstance(img, np.ndarray):
img = Image.fromarray(img)
img.save(buffer, format="PNG")
img_bytes = buffer.getvalue()
img_base64 = base64.b64encode(img_bytes).decode("utf-8")
Expand Down