'commit'
This commit is contained in:
@@ -7,7 +7,7 @@ import uuid
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, root_validator
|
||||
|
||||
from Config.Config import OBS_PREFIX, OBS_BUCKET, OBS_SERVER
|
||||
from QWenImage.QWenImageEditKit import QwenImageEditor
|
||||
@@ -36,10 +36,9 @@ class GenerateImageRequest(BaseModel):
|
||||
class EditImageRequest(BaseModel):
|
||||
"""编辑图片请求模型"""
|
||||
prompt: str = Field(..., description="编辑提示词")
|
||||
size: str = Field(default="1328*1328", description="图片尺寸")
|
||||
api_key: Optional[str] = Field(default=None, description="自定义API密钥")
|
||||
# 支持URL或Base64两种格式,二选一
|
||||
image_url: Optional[str] = Field(default=None, description="原始图片URL")
|
||||
# 仅保留URL方式,设为必填项
|
||||
image_url: str = Field(..., description="原始图片URL")
|
||||
image_base64: Optional[str] = Field(default=None, description="原始图片Base64编码")
|
||||
|
||||
@root_validator(pre=True)
|
||||
@@ -145,16 +144,16 @@ async def edit_image(request: EditImageRequest):
|
||||
dict: 包含编辑结果的字典
|
||||
"""
|
||||
try:
|
||||
# 恢复为仅使用image_url的日志记录
|
||||
logger.info(f"接收到图片编辑请求: image_url={request.image_url[:50]}..., prompt={request.prompt[:50]}...")
|
||||
|
||||
# 如果提供了自定义API密钥,创建新的编辑器实例
|
||||
editor = QwenImageEditor(api_key=request.api_key) if request.api_key else image_editor
|
||||
|
||||
# 调用图片编辑API
|
||||
# 使用image_url参数调用编辑接口
|
||||
result = editor.edit_image(
|
||||
image_url=request.image_url,
|
||||
prompt=request.prompt,
|
||||
negative_prompt=request.negative_prompt
|
||||
prompt=request.prompt
|
||||
)
|
||||
|
||||
# 处理结果
|
||||
|
Reference in New Issue
Block a user