From 8c64b5d650a6eb925d97b93f7a51d527525393e9 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Wed, 16 Apr 2025 12:59:32 +0800 Subject: [PATCH] update --- app/api/v1/tryon.py | 22 +++------------------- app/models/tryon.py | 7 +------ app/schemas/tryon.py | 6 +----- 3 files changed, 5 insertions(+), 30 deletions(-) diff --git a/app/api/v1/tryon.py b/app/api/v1/tryon.py index 3f81c7a..87ff27a 100644 --- a/app/api/v1/tryon.py +++ b/app/api/v1/tryon.py @@ -42,23 +42,11 @@ async def tryon( if not person_image: raise HTTPException(status_code=404, detail="默认形象不存在") - # 获取试穿请求中的衣物ID - top_clothing_id = tryon_request.top_clothing_id - bottom_clothing_id = tryon_request.bottom_clothing_id - + # 获取衣物详情 top_clothing_url = tryon_request.top_clothing_url bottom_clothing_url = tryon_request.bottom_clothing_url - if top_clothing_id: - top_clothing = await clothing_service.get_clothing(db, top_clothing_id) - top_clothing_url = top_clothing.image_url - - if bottom_clothing_id: - bottom_clothing = await clothing_service.get_clothing(db, bottom_clothing_id) - bottom_clothing_url = bottom_clothing.image_url - - # 调用试穿服务 dashscope_service = DashScopeService() tryon_result = await dashscope_service.generate_tryon(person_image.image_url, @@ -69,9 +57,7 @@ async def tryon( if task_id: tryon_history = TryonHistory( user_id=current_user.id, - person_image_id=person_image.id, - top_clothing_id=top_clothing_id, - bottom_clothing_id=bottom_clothing_id, + person_image_url=person_image.image_url, top_clothing_url=top_clothing_url, bottom_clothing_url=bottom_clothing_url, task_id=task_id, @@ -98,11 +84,9 @@ async def get_tryon_histories( for history in tryon_histories: item = { "id": history.id, - "person_image": PersonImage.model_validate(history.person_image), + "person_image_url": history.person_image_url, "top_clothing_url": history.top_clothing_url, "bottom_clothing_url": history.bottom_clothing_url, - "top_clothing_id": history.top_clothing_id, - "bottom_clothing_id": history.bottom_clothing_id, "status": history.status, "task_id": history.task_id, "completion_url": history.completion_url, diff --git a/app/models/tryon.py b/app/models/tryon.py index e78a5d3..b53097a 100644 --- a/app/models/tryon.py +++ b/app/models/tryon.py @@ -16,9 +16,7 @@ class TryonHistory(Base): id = Column(Integer, primary_key=True, autoincrement=True, index=True) user_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True, comment="用户ID") - person_image_id = Column(Integer, ForeignKey("person_images.id"), nullable=False, index=True, comment="人物形象ID") - top_clothing_id = Column(Integer, ForeignKey("clothing.id"), nullable=True, comment="上衣ID") - bottom_clothing_id = Column(Integer, ForeignKey("clothing.id"), nullable=True, comment="下装ID") + person_image_url = Column(String(500), nullable=False, comment="人物形象图片URL") top_clothing_url = Column(String(500), nullable=True, comment="上衣图片URL") bottom_clothing_url = Column(String(500), nullable=True, comment="下装图片URL") task_id = Column(String(100), nullable=True, index=True, comment="任务ID") @@ -31,9 +29,6 @@ class TryonHistory(Base): # 关系 user = relationship("User", backref="tryon_histories") - person_image = relationship("PersonImage", backref="tryon_histories") - top_clothing = relationship("Clothing", foreign_keys=[top_clothing_id], backref="top_tryon_histories") - bottom_clothing = relationship("Clothing", foreign_keys=[bottom_clothing_id], backref="bottom_tryon_histories") def __repr__(self): return f"" \ No newline at end of file diff --git a/app/schemas/tryon.py b/app/schemas/tryon.py index 02e77d4..c4f5f07 100644 --- a/app/schemas/tryon.py +++ b/app/schemas/tryon.py @@ -5,17 +5,13 @@ from datetime import datetime class TryonRequest(BaseModel): - top_clothing_id: Optional[int] = None - bottom_clothing_id: Optional[int] = None top_clothing_url: Optional[str] = None bottom_clothing_url: Optional[str] = None class TryonHistoryModel(BaseModel): id: int - person_image_id: Optional[int] = None - top_clothing_id: Optional[int] = None - bottom_clothing_id: Optional[int] = None + person_image_url: Optional[str] = None top_clothing_url: Optional[str] = None bottom_clothing_url: Optional[str] = None status: TryonStatus