This commit is contained in:
aaron 2025-04-16 12:59:32 +08:00
parent 02c8d7f8ba
commit 8c64b5d650
3 changed files with 5 additions and 30 deletions

View File

@ -42,23 +42,11 @@ async def tryon(
if not person_image: if not person_image:
raise HTTPException(status_code=404, detail="默认形象不存在") 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 top_clothing_url = tryon_request.top_clothing_url
bottom_clothing_url = tryon_request.bottom_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() dashscope_service = DashScopeService()
tryon_result = await dashscope_service.generate_tryon(person_image.image_url, tryon_result = await dashscope_service.generate_tryon(person_image.image_url,
@ -69,9 +57,7 @@ async def tryon(
if task_id: if task_id:
tryon_history = TryonHistory( tryon_history = TryonHistory(
user_id=current_user.id, user_id=current_user.id,
person_image_id=person_image.id, person_image_url=person_image.image_url,
top_clothing_id=top_clothing_id,
bottom_clothing_id=bottom_clothing_id,
top_clothing_url=top_clothing_url, top_clothing_url=top_clothing_url,
bottom_clothing_url=bottom_clothing_url, bottom_clothing_url=bottom_clothing_url,
task_id=task_id, task_id=task_id,
@ -98,11 +84,9 @@ async def get_tryon_histories(
for history in tryon_histories: for history in tryon_histories:
item = { item = {
"id": history.id, "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, "top_clothing_url": history.top_clothing_url,
"bottom_clothing_url": history.bottom_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, "status": history.status,
"task_id": history.task_id, "task_id": history.task_id,
"completion_url": history.completion_url, "completion_url": history.completion_url,

View File

@ -16,9 +16,7 @@ class TryonHistory(Base):
id = Column(Integer, primary_key=True, autoincrement=True, index=True) id = Column(Integer, primary_key=True, autoincrement=True, index=True)
user_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True, comment="用户ID") 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") person_image_url = Column(String(500), nullable=False, comment="人物形象图片URL")
top_clothing_id = Column(Integer, ForeignKey("clothing.id"), nullable=True, comment="上衣ID")
bottom_clothing_id = Column(Integer, ForeignKey("clothing.id"), nullable=True, comment="下装ID")
top_clothing_url = Column(String(500), nullable=True, comment="上衣图片URL") top_clothing_url = Column(String(500), nullable=True, comment="上衣图片URL")
bottom_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") task_id = Column(String(100), nullable=True, index=True, comment="任务ID")
@ -31,9 +29,6 @@ class TryonHistory(Base):
# 关系 # 关系
user = relationship("User", backref="tryon_histories") 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): def __repr__(self):
return f"<TryonHistory(id={self.id}, status={self.status.name})>" return f"<TryonHistory(id={self.id}, status={self.status.name})>"

View File

@ -5,17 +5,13 @@ from datetime import datetime
class TryonRequest(BaseModel): class TryonRequest(BaseModel):
top_clothing_id: Optional[int] = None
bottom_clothing_id: Optional[int] = None
top_clothing_url: Optional[str] = None top_clothing_url: Optional[str] = None
bottom_clothing_url: Optional[str] = None bottom_clothing_url: Optional[str] = None
class TryonHistoryModel(BaseModel): class TryonHistoryModel(BaseModel):
id: int id: int
person_image_id: Optional[int] = None person_image_url: Optional[str] = None
top_clothing_id: Optional[int] = None
bottom_clothing_id: Optional[int] = None
top_clothing_url: Optional[str] = None top_clothing_url: Optional[str] = None
bottom_clothing_url: Optional[str] = None bottom_clothing_url: Optional[str] = None
status: TryonStatus status: TryonStatus