# Prompt2Icon **Repository Path**: xu-zhanwei/prompt2-icon ## Basic Information - **Project Name**: Prompt2Icon - **Description**: 调用在问API,根据提示词生成相应的图标 - **Primary Language**: Python - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-09-29 - **Last Updated**: 2024-09-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Prompt2Icon #### 介绍 调用在问API,根据提示词生成相应的图标 #### 软件架构 [API获取地址](https://gitee.com/xu-zhanwei/chatanywhere/blob/master/api.md) * 我们利用在问提供的问答API,使用 `gpt-4o-mini` 模型,让 AI 学习理解每个角色的功能,并生成简洁精准的图标描述语句。 ```python def get_prompt(system_prompt): # ... (代码省略) message = f''' 你是一个图标描述生成器,基于下面的文字内容生成一个合适的图标的简洁的描述,给出对应的这个合适的图标的一种描述, 这个图标可以是一个头像,也可以是一个角色,也可以是一个动物,也可以是一种符号。总而言之,能够比较好的概括,上面所承担的这样一个内容。简洁一点,然后多用一些描述一张图像的内容而少去表达一种情感或怎么样。 多需用一种色彩,视觉上的词汇来表述你的这个图标。开头是:一个简洁图标 下面是原来的文字内容 \''' {system_prompt} \''' ''' # ... (代码省略) return text_all ``` * 然后,我们利用 `zaiwen` 的图像生成API,使用 `flux-schnell` 模型,将 AI 生成的描述语句转化为精美的图标。 ```python def get_img_url(prompt): # ... (代码省略) data = { "prompt": prompt, # ... (代码省略) } response = requests.post(url, headers=headers, data=json.dumps(data)) # ... (代码省略) return image_url ``` * 最后,我们对生成的图标进行裁剪、缩放等处理,确保每个图标都清晰、美观,完美匹配对应的角色。 ```python def process_img_url(img_url: str) -> str: # ... (代码省略) img_cropped = img.crop((left, top, right, bottom)) # ... (代码省略) return uploaded_url ```