Replies: 1 comment
-
|
The Code Execution node in Dify cannot output file-type variables - this is a fundamental architectural limitation. Even if you construct a dict with Recommended Workaround - Base64 Encoding: from PIL import Image
import io
import base64
import requests
from io import BytesIO
def main(input_files: list) -> dict:
results = []
for file in input_files:
url = file.get('remote_url') or file.get('url')
response = requests.get(url)
img = Image.open(BytesIO(response.content))
# Resize and convert to grayscale
img = img.resize((512, 512))
img = img.convert('L')
# Convert to base64
buffer = BytesIO()
img.save(buffer, format='PNG')
buffer.seek(0)
image_base64 = base64.b64encode(buffer.read()).decode('utf-8')
results.append(image_base64)
return {"image_base64": results[0] if results else ""}Set your output variable type to Limitation: String outputs are limited to 80,000 characters, which constrains image resolution. Alternative: If you need proper file-type output, consider creating a custom tool/plugin instead - tool nodes have native support for file outputs that Code nodes lack. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Self Checks
1. Is this request related to a challenge you're experiencing? Tell me about your story.
Hello everyone, I encountered an issue while using DIY to implement a text generated image and adjusting the image size to grayscale through code execution nodes before inputting the image. The specific workflow is shown in the following figure:
The screenshot is as follows:
The output of Qwen Wensheng diagram is:
{ "text": "🚀 文生图任务启动中...🤖 使用模型: qwen-image-max📝 提示词: <think>\n好的,用户让我画一只赤狐在秋日枫林里前行,火红的尾巴扫过满地落叶。首先,我需要处理输...📐 图像尺寸: 1328*1328⏳ 正在连接通义API...🎨 正在生成图像,请稍候...🎉 图像生成成功!✅ 第 1 张图片生成完成!📊 使用统计: - height: 1328 - image_count: 1 - width: 1328🎯 文生图任务完成!", "files": [ { "dify_model_identity": "__dify__file__", "id": null, "tenant_id": "623ea70f-2287-40cc-82d5-485d28b73416", "type": "image", "transfer_method": "tool_file", "remote_url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/7d/88/20260306/d23adf3d/b427ad8a-ae9d-4a45-9d9c-088e3523caea411034012.png?Expires=1773374162&OSSAccessKeyId=LTAI5tKPD3TMqf2Lna1fASuh&Signature=avWwL0g0vvZO50HJkjLXx9OCe6w%3D", "related_id": "b8c811c3-b051-400b-aefb-3fe278c36b4b", "filename": "1f49910a28fe4525a9eac152b76bde36.png", "extension": ".png", "mime_type": "image/png", "size": 3288905, "url": "/files/tools/b8c811c3-b051-400b-aefb-3fe278c36b4b.png?timestamp=1772768363&nonce=80477c8f8c0168076a2eafe57f5eef81&sign=uIUZfFamJbfaVko39So-k0ygKhwqDVBf2VUg5KtmaKc=" } ], "json": [ { "data": [] } ] }2. Additional context or comments
And I found that when the "Qwen Wensheng Graph" node outputs, as long as it is directly connected to the "output" node and the output variable of the "output" node is selected as
files array[file],The image can be obtained,However, the 'code execution' node does not have an output variable for 'files array [file]', only the following output variables:
So did I choose the wrong output variable for the 'code execution' node? How can I operate to make the 'output' node output an image, similar to 'Qwen Wensheng Graph' directly connecting to the 'output' node to obtain an image.
Beta Was this translation helpful? Give feedback.
All reactions