新增flux2 klein 图像生成模型
This commit is contained in:
2
main.py
2
main.py
@@ -7,6 +7,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
||||
from logging_env import LOGGER_CONFIG_DICT
|
||||
from src.routers import chat, deep_agent_chat
|
||||
from src.routers import generate_3D
|
||||
from src.routers import flux2_gen_img
|
||||
|
||||
logging.config.dictConfig(LOGGER_CONFIG_DICT)
|
||||
|
||||
@@ -28,6 +29,7 @@ app_server.add_middleware(
|
||||
app_server.include_router(chat.router)
|
||||
app_server.include_router(deep_agent_chat.router)
|
||||
app_server.include_router(generate_3D.router)
|
||||
app_server.include_router(flux2_gen_img.router)
|
||||
|
||||
|
||||
@app_server.get("/")
|
||||
|
||||
@@ -34,6 +34,7 @@ class Settings(BaseSettings):
|
||||
|
||||
# --- 本地服务器配置信息 ---
|
||||
IMAGE_TO_3D_MODEL_URL: str = Field(default='', description="")
|
||||
FLUX2_GEN_IMG_MODEL_URL: str = Field(default='', description="")
|
||||
|
||||
# --- 外部工具api配置信息 ---
|
||||
TAVILY_API_KEY: str = Field(default="", description="")
|
||||
|
||||
72
src/routers/flux2_gen_img.py
Normal file
72
src/routers/flux2_gen_img.py
Normal file
@@ -0,0 +1,72 @@
|
||||
import json
|
||||
import logging
|
||||
import httpx
|
||||
from fastapi import APIRouter
|
||||
|
||||
from src.core.config import settings
|
||||
from src.schemas.flux2_gen_img import Flux2_Gen_Img_Model
|
||||
from src.schemas.response_template import ResponseModel
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
router = APIRouter(prefix="/canvas", tags=["Furniture Canvas"])
|
||||
|
||||
|
||||
@router.post("/flux2_gen_img")
|
||||
async def flux2_gen_img(request_data: Flux2_Gen_Img_Model):
|
||||
"""
|
||||
### 参数说明:
|
||||
|
||||
- **bucket_name**: OSS桶名 (必填)
|
||||
- **object_name**: OSS对象名(文件路径)(必填)
|
||||
|
||||
- **input_image_paths**: 输入图片路径列表 (非必填,默认[])
|
||||
- **width**: 图片宽度,默认512像素 (非必填,默认512)
|
||||
- **height**: 图片高度,默认512像素 (非必填,默认512)
|
||||
- **prompt**: 文本提示词,用于模型推理等场景 (非必填,默认"")
|
||||
- **steps**: 推理步数,控制模型生成过程的迭代次数 (非必填,默认4)
|
||||
- **guidance**: 引导系数,调节提示词对生成结果的影响程度 (非必填,默认 4.0 )
|
||||
|
||||
### 请求体示例:
|
||||
```
|
||||
{
|
||||
"input_image_paths": ["test/typical_building_space_station.png","test/typical_creature_dragon.png"],
|
||||
"width": 512,
|
||||
"height": 512,
|
||||
"bucket_name": "my-oss-bucket",
|
||||
"object_name": "generated_images/result.jpg",
|
||||
"prompt": "a beautiful landscape with mountains and rivers",
|
||||
"steps": 4,
|
||||
"guidance": 4.0
|
||||
}
|
||||
````
|
||||
|
||||
### 输出示例:
|
||||
```
|
||||
{
|
||||
"code": 200,
|
||||
"msg": "OK!",
|
||||
"data": {
|
||||
"output_path": "test/generated_images/result.jpg"
|
||||
}
|
||||
}
|
||||
```
|
||||
"""
|
||||
try:
|
||||
logger.info(
|
||||
f"flux2_gen_img request: {json.dumps(request_data.model_dump(), indent=4)}"
|
||||
)
|
||||
|
||||
async with httpx.AsyncClient(timeout=120) as client:
|
||||
resp = await client.post(
|
||||
f"http://{settings.FLUX2_GEN_IMG_MODEL_URL}/predict",
|
||||
json=request_data.model_dump(),
|
||||
)
|
||||
|
||||
result = resp.json()
|
||||
|
||||
logger.info(f"flux2_gen_img response: {json.dumps(result, indent=4)}")
|
||||
|
||||
return ResponseModel(data=result)
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"img_to_3D Run Exception: {e}")
|
||||
14
src/schemas/flux2_gen_img.py
Normal file
14
src/schemas/flux2_gen_img.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class Flux2_Gen_Img_Model(BaseModel):
|
||||
input_image_paths: Optional[List[str]] = Field(..., description="输入图片路径列表")
|
||||
width: Optional[int] = Field(default=512, description="图片宽度,默认512像素")
|
||||
height: Optional[int] = Field(default=512, description="图片高度,默认512像素")
|
||||
bucket_name: Optional[str] = Field(default="", description="OSS桶名,不传则为None")
|
||||
object_name: Optional[str] = Field(default="", description="OSS对象名(文件路径),不传则为None")
|
||||
prompt: Optional[str] = Field(default="", description="文本提示词,用于模型推理等场景")
|
||||
steps: Optional[int] = Field(default=4, description="推理步数,控制模型生成过程的迭代次数")
|
||||
guidance: Optional[float] = Field(default=4.0, description="引导系数,调节提示词对生成结果的影响程度")
|
||||
Reference in New Issue
Block a user