import os from openai import OpenAI from PIL import Image from io import BytesIO import base64 import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from config import api_key, base_url # OpenAI API configuration API_KEY = api_key API_PROVIDER = base_url client = OpenAI( api_key=API_KEY, base_url=API_PROVIDER, ) from openai import OpenAI import base64 import os client = OpenAI( api_key=API_KEY, base_url=API_PROVIDER ) result = client.images.generate( model="gpt-image-1", prompt=prompt, n=1, # 单次出图数量,最多 10 张 size="1024x1024", # 1024x1024 (square), 1536x1024 (3:2 landscape), 1024x1536 (2:3 portrait), auto (default) quality="low", # high, medium, low, auto (default) moderation="low", # low, auto (default) 需要升级 openai 包 📍 background="auto", # transparent, opaque, auto (default) ) design_prompt_template = """ [TASK START] OBJECTIVE: Generate a text-to-image prompt for a single, isolated clipart icon based on the provided inputs. INPUTS: Topic: TOPIC_PLACEHOLDER Style Keyword: STYLE_KEYWORD_PLACEHOLDER PROCESS: Conceptualize: First, determine a single, specific, and universally recognizable visual concept (a concrete object or scene) that best represents the broad Topic. Generate: Second, write a text-to-image prompt describing this visual concept, rendered using the specified Style Keyword. CONSTRAINTS: The output must be a single icon or a small, unified group of objects. The icon MUST be isolated on a plain white background. The final prompt must be concise and descriptive. REQUIRED OUTPUT: (Provide your answer in this exact structure) Selected Concept: [The specific visual metaphor you chose for the topic] Image Prompt: [The final text-to-image prompt] [TASK END] """