fix image
All checks were successful
Build and Deploy Backend / build-and-deploy (push) Successful in 5m17s

This commit is contained in:
repair-agent 2026-03-24 18:19:25 +08:00
parent fe0dcb78c3
commit f6d1559c90
2 changed files with 18 additions and 23 deletions

View File

@ -148,26 +148,20 @@ def generate_i2i_stream(user, badge_image, image_bytes, prompt='', style=None,
image_model = config.get('IMAGE_MODEL_NAME', 'doubao-seedream-4-5-251128')
image_size = f'{width}x{height}'
# 尝试带参考图的生成,若 SDK 不支持则回退到纯文生图
try:
result = client.images.generate(
model=image_model,
prompt=full_prompt,
size=image_size,
response_format='url',
watermark=False,
reference_image=ref_url,
reference_strength=strength,
)
except TypeError:
logger.warning('Seedream SDK does not support reference_image, falling back to t2i')
result = client.images.generate(
model=image_model,
prompt=full_prompt,
size=image_size,
response_format='url',
watermark=False,
)
# 将前端 strength(0.1~1.0) 映射到 guidance_scale(1.0~20.0)
# strength 越大 → 越贴近参考图 → guidance_scale 越低(更依赖图片)
# strength 越小 → 越自由发挥 → guidance_scale 越高(更依赖提示词)
guidance = 1.0 + (1.0 - strength) * 19.0
result = client.images.generate(
model=image_model,
prompt=full_prompt,
size=image_size,
response_format='url',
watermark=False,
image=ref_url,
guidance_scale=guidance,
)
temp_url = result.data[0].url

View File

@ -40,12 +40,13 @@ class DeviceBatchCreateSerializer(serializers.ModelSerializer):
class DeviceSerializer(serializers.ModelSerializer):
"""设备序列化器"""
device_type = DeviceTypeSerializer(read_only=True)
device_type_info = DeviceTypeSerializer(source='device_type', read_only=True)
class Meta:
model = Device
fields = ['id', 'sn', 'device_type', 'device_type_info', 'mac_address',
fields = ['id', 'sn', 'device_type', 'device_type_info', 'mac_address',
'name', 'status', 'firmware_version', 'last_online_at', 'created_at']