| from fastapi import APIRouter, File, UploadFile, HTTPException, Form |
| from fastapi.responses import StreamingResponse |
| from app.services.image_generation_service import generate_image_from_files_and_prompt |
| from app.services.prompt_factory import MULTI_VIEW_TEMPLATE |
| from app.schemas.common_schemas import ModelSchema, CameraSchema,GarmentType |
| import io |
| from typing import List, Annotated |
|
|
| router = APIRouter() |
| |
| @router.post("/multi_view", tags=["Multi_view"]) |
| async def multi_view( |
| garment_images: List[UploadFile] = File(..., description="Exactly one image of the garments (e.g., dress /bag/shoes).", min_items=1, max_items=1), |
| ): |
| |
| |
| if not garment_images or len(garment_images) != 1: |
| raise HTTPException(status_code=400, detail="Exactly one garment images are required for outfit match.") |
|
|
| image_bytes_list = [] |
| for image_file in garment_images: |
| if not image_file.content_type.startswith("image/"): |
| raise HTTPException(status_code=400, detail=f"Invalid file type for garment: {image_file.filename}. Must be an image.") |
| content = await image_file.read() |
| image_bytes_list.append((content, image_file.filename)) |
| |
| prompt=MULTI_VIEW_TEMPLATE |
|
|
| generated_image_data = await generate_image_from_files_and_prompt( |
| image_files=image_bytes_list, |
| prompt=prompt |
| ) |
|
|
| if generated_image_data: |
| return StreamingResponse(io.BytesIO(generated_image_data), media_type="image/png") |
| else: |
| raise HTTPException(status_code=500, detail="Failed to generate image. Check service logs.") |
|
|