From 890ce33d291f9e7ed8d8dee7b11596ed1bd7a0be Mon Sep 17 00:00:00 2001
From: Xinfan Chen <2024111082@stu.hit.edu.cn>
Date: Thu, 23 Apr 2026 14:39:32 +0800
Subject: [PATCH] 简化gpt-image调用
---
aigc-director/aigc-claw/backend/tool/image_client.py | 75 +++++++++++++++++++++++++++++--------
1 files changed, 59 insertions(+), 16 deletions(-)
diff --git a/aigc-director/aigc-claw/backend/tool/image_client.py b/aigc-director/aigc-claw/backend/tool/image_client.py
index 81011ec..f8a2b67 100644
--- a/aigc-director/aigc-claw/backend/tool/image_client.py
+++ b/aigc-director/aigc-claw/backend/tool/image_client.py
@@ -12,11 +12,11 @@
from tool.image_gpt import ImageGPT
from tool.image_processor import ImageProcessor
except ImportError:
- from image_dashscope import DashScopeClient
- from image_jimeng import JiMengClient
- from image_seedream import SeedreamClient
- from image_gpt import ImageGPT
- from image_processor import ImageProcessor
+ from .image_dashscope import DashScopeClient
+ from .image_jimeng import JiMengClient
+ from .image_seedream import SeedreamClient
+ from .image_gpt import ImageGPT
+ from .image_processor import ImageProcessor
class ImageClient:
def __init__(self,
@@ -27,7 +27,6 @@
jimeng_secret_key: Optional[str] = None,
gpt_api_key: Optional[str] = None,
gpt_base_url: Optional[str] = None,
- gpt_official_api_key: Optional[str] = None,
local_proxy: Optional[str] = None,
ark_api_key: Optional[str] = None,
ark_base_url: Optional[str] = None):
@@ -58,8 +57,7 @@
self.gpt_client = ImageGPT(
api_key=gpt_api_key,
base_url=gpt_base_url,
- official_api_key=gpt_official_api_key or '',
- local_proxy=local_proxy or ''
+ local_proxy=local_proxy
)
# Initialize Image Processor for downloads
@@ -68,27 +66,66 @@
# Default save directory
self.base_save_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "code", "result", "image_client")
- def generate_image(self,
- prompt: str,
- image_paths: Optional[List[str]] = None,
+ def generate_image(self,
+ prompt: str,
+ image_paths: Optional[List[str]] = None,
model: str = "wan2.6-t2i",
save_dir: Optional[str] = None,
session_id: Optional[str] = None,
- size: Optional[str] = "1920*1080") -> List[str]:
+ video_ratio: Optional[str] = "16:9",
+ resolution: Optional[str] = "4K") -> List[str]:
"""
Generate images based on prompt and optional reference images.
-
+
Args:
prompt: Text prompt for generation.
image_paths: List of local file paths or URLs for reference images.
model: Model name to determine which provider to use.
save_dir: Custom directory to save downloaded images.
session_id: Session ID for organizing saved files (especially for JiMeng)
- size: Desired size of the generated image, e.g., "1024*1024" or "1920*1080".
-
+ video_ratio: Aspect ratio of the video, e.g., "16:9", "9:16", "4:3", "3:4", "1:1".
+ resolution: Resolution string, e.g., "720P", "1080P", "2K", "4K".
+
Returns:
List of absolute file paths of the generated images.
"""
+ # Determine size from video_ratio and resolution
+ size_map = {
+ "16:9": {
+ "720P": "1280*720",
+ "1080P": "1920*1080",
+ "2K": "2560*1440",
+ "4K": "3840*2160"
+ },
+ "9:16": {
+ "720P": "720*1280",
+ "1080P": "1080*1920",
+ "2K": "1440*2560",
+ "4K": "2160*3840"
+ },
+ "4:3": {
+ "720P": "960*720",
+ "1080P": "1440*1080",
+ "2K": "2560*1920",
+ "4K": "3840*2880"
+ },
+ "3:4": {
+ "720P": "720*960",
+ "1080P": "1080*1440",
+ "2K": "1920*2560",
+ "4K": "2880*3840"
+ },
+ "1:1": {
+ "720P": "720*720",
+ "1080P": "1080*1080",
+ "2K": "2560*2560",
+ "4K": "3840*3840"
+ }
+ }
+
+ # Default fallback if ratio or resolution is not found
+ size = size_map.get(video_ratio, size_map["16:9"]).get(resolution, "1920*1080")
+
if not model:
model = "wan2.6-t2i"
@@ -98,8 +135,14 @@
if image_paths:
print(f"Refs: {len(image_paths)}")
for p in image_paths:
- print(f" - {p}")
+ if str(p).startswith("data:"):
+ print(f" - [Base64图片]")
+ else:
+ print(f" - {p}")
print(f"Model: {model}")
+ print(f"Video Ratio: {video_ratio}")
+ print(f"Resolution: {resolution}")
+ print(f"Final Size: {size}")
if session_id:
print(f"Session ID: {session_id}")
print("-" * 30)
--
Gitblit v1.8.0