This commit is contained in:
@@ -35,13 +35,14 @@ class ImageGenerator:
|
|||||||
system_prompt = """你是一个AI图像提示词优化专家。你的任务是将用户的语音识别结果转化为适合生成"黑白线稿"的提示词。
|
system_prompt = """你是一个AI图像提示词优化专家。你的任务是将用户的语音识别结果转化为适合生成"黑白线稿"的提示词。
|
||||||
关键要求:
|
关键要求:
|
||||||
1. 风格必须是:简单的黑白线稿、简笔画、图标风格 (Line art, Sketch, Icon style)。
|
1. 风格必须是:简单的黑白线稿、简笔画、图标风格 (Line art, Sketch, Icon style)。
|
||||||
2. 画面必须清晰、线条粗壮,适合低分辨率热敏打印机打印。
|
2. 画面必须清晰、线条粗壮,适合低分辨率热敏打印机打印,用来生成标签贴纸。
|
||||||
3. 绝对不要有复杂的阴影、渐变、黑白线条描述。
|
3. 绝对不要有复杂的阴影、渐变、黑白线条描述。
|
||||||
4. 背景必须是纯白 (White background)。
|
4. 背景必须是纯白 (White background)。
|
||||||
5. 提示词内容请使用英文描述,因为绘图模型对英文生成要更准确。
|
5. 提示词内容请使用英文描述,因为绘图模型对英文生成要更准确。
|
||||||
6. 尺寸比例遵循宽48mm:高30mm (约 1.6:1)。
|
6. 尺寸比例遵循宽48mm:高30mm (约 1.6:1)。
|
||||||
7. 直接输出优化后的提示词,不要包含任何解释。
|
7. 直接输出优化后的提示词,不要包含任何解释。
|
||||||
如果用户要求输入文字,则用```把文字包裹起来,文字是中文
|
如果用户要求输入文字,则用```把文字包裹起来,如果用户有中文文字,则用中文包裹起来。所有文字都是中文,描述都是英文。
|
||||||
|
example:
|
||||||
"A house with a child on the side, black and white line art, cartoon style, text:```中国人``` below."
|
"A house with a child on the side, black and white line art, cartoon style, text:```中国人``` below."
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -275,7 +275,10 @@ async def send_image_to_client(websocket: WebSocket, image_path: str):
|
|||||||
print(f"Sending image to ESP32, size: {len(image_data)} bytes")
|
print(f"Sending image to ESP32, size: {len(image_data)} bytes")
|
||||||
|
|
||||||
# Send start marker
|
# Send start marker
|
||||||
await websocket.send_text(f"IMAGE_START:{len(image_data)}:{THUMB_SIZE}")
|
model_name = f"{image_generator.provider}"
|
||||||
|
if image_generator.model:
|
||||||
|
model_name += f" {image_generator.model}"
|
||||||
|
await websocket.send_text(f"IMAGE_START:{len(image_data)}:{THUMB_SIZE}:{model_name}")
|
||||||
|
|
||||||
# Send binary data directly
|
# Send binary data directly
|
||||||
chunk_size = 512 # Decreased chunk size for ESP32 memory stability
|
chunk_size = 512 # Decreased chunk size for ESP32 memory stability
|
||||||
@@ -594,8 +597,23 @@ def generate_image(prompt, progress_callback=None, retry_count=0, max_retries=2)
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
img = Image.open(GENERATED_IMAGE_FILE)
|
img = Image.open(GENERATED_IMAGE_FILE)
|
||||||
|
|
||||||
# 缩小到THUMB_SIZE x THUMB_SIZE
|
# 保持比例缩放
|
||||||
img = img.resize((THUMB_SIZE, THUMB_SIZE), Image.LANCZOS)
|
# Calculate aspect ratio
|
||||||
|
ratio = min(THUMB_SIZE / img.width, THUMB_SIZE / img.height)
|
||||||
|
new_width = int(img.width * ratio)
|
||||||
|
new_height = int(img.height * ratio)
|
||||||
|
|
||||||
|
resized_img = img.resize((new_width, new_height), Image.LANCZOS)
|
||||||
|
|
||||||
|
# Create black background
|
||||||
|
final_img = Image.new("RGB", (THUMB_SIZE, THUMB_SIZE), (0, 0, 0))
|
||||||
|
|
||||||
|
# Paste centered
|
||||||
|
x_offset = (THUMB_SIZE - new_width) // 2
|
||||||
|
y_offset = (THUMB_SIZE - new_height) // 2
|
||||||
|
|
||||||
|
final_img.paste(resized_img, (x_offset, y_offset))
|
||||||
|
img = final_img
|
||||||
|
|
||||||
# 转换为RGB565格式的原始数据
|
# 转换为RGB565格式的原始数据
|
||||||
# 每个像素2字节 (R5 G6 B5)
|
# 每个像素2字节 (R5 G6 B5)
|
||||||
|
|||||||
Reference in New Issue
Block a user