通过稳定的扩散API和Printfy API增强销售的最终指南
#python #openai #chatgpt #stablediffusio

使用稳定的扩散API和PRINTFY API:分解过程

github。 :https://github.com/lokeshvelayudham/stability-printfyapiAi

有关更多与我联系 @ Linkedin

Image description

如果您在AI的世界中,您可能听说过稳定的
扩散。这是一个强大的工具,可将文本转换为高分辨率,高质量的图像。借助易于使用的平台和动态的用户社区,它已成为数字景观中的杰出工具。

使用稳定的扩散AI生成图像并使用PrintFy API将其发布在Printfy -Shopify Store

稳定的扩散提供了一个API来生成文本以形象生成的AI,其中图像存储在本地/牛Mongodb中,并使用PrintFy API 将这些图像上传到商店

要生成图像,我们正在使用稳定性扩散 -
我们将需要开放的API密钥和稳定性扩散AI键
生成图像并存储的功能
Image description

`对于IDX,tqdm中的行(df.iterrows(),total = df.shape [0]):
详细信息=行['详细信息']

# Generate the title, description, prompt, and tags using the OpenAI API
title = generate_clickable_title(detail)
description = generate_description(detail)
image_prompt = generate_image_prompt(detail)
tag = generate_tags(detail)



# Generate the image using the Stability.ai API
url = "https://api.stability.ai/v1/generation/stable-diffusion-v1-5/text-to-image"
headers = {"Authorization": f"Bearer {stability_ai_key}", "Accept": "image/png"}
data = {
    "width": 512,
    "height": 512,
    "text_prompts": [
        {
            "text": image_prompt,
            "weight": 0.5
        }
    ]
}
response = requests.post(url, headers=headers, json=data)
image_data = response.content
image = Image.open(io.BytesIO(image_data))
file_name = f"image_{idx}.png"  
local_path = f"{file_name}"  # Save the image in the same directory
image.save(local_path)

# Append the generated data to the lists
file_names.append(file_name)
local_paths.append(local_path)
titles.append(title)
descriptions.append(description)
tags.append(tag)`

将产品上传到Shopify Printify网站

Image description

# To change the print object, use this to find the variant id curl -X GET "https://api.printify.com/v1/catalog/blueprints/1098/print_providers/228/variants.json" "Authorization: Bearer {access token}"

通过运行以下操作:curl -x获取https://api.printify.com/v1/shops.json -Header“授权:bearer {access token}”来查找您的商店ID。

`对于IDX,image_df.iterrows()中的行:
#将图像转换为base64
随着打开(row ['local_path'],“ rb”)作为img_file:
img_b64 = base64.b64encode(img_file.read())。解码('utf-8')

# Upload the image to the Printify media library
data = {
    "file_name": row['file_name'],
    "contents": img_b64
}
response = requests.post(upload_url, headers=headers, json=data)
image_id = response.json()["id"]

#当前设置用于墙壁艺术

# Create the product with the uploaded image
data = {
    "title": row['title'],
    "description": row['description'],
    "tags": row['tags'].split(', '),  # Assuming tags are comma-separated in the CSV
    "blueprint_id": 6,  # Replace with the actual blueprint ID
    "print_provider_id": 270,
    "variants": [
        {
            "id": 12126,  # Replace with the actual variant ID
            "price": 3999,
            "is_enabled": True
        }
    ],
    "print_areas": [
        {
            "variant_ids": [82064],  # Replace with the actual variant ID
            "placeholders": [
                {
                    "position": "front",
                    "height": 3761,
                    "width": 3319,
                    "images": [
                        {
                            "id": image_id,
                            "x": 0.5,
                            "y": 0.5,
                            "scale": 1.5,
                            "angle": 0
                        }
                    ]
                }
            ]
        }
    ]
}
response = requests.post(product_url, headers=headers, json=data)
if response.status_code >= 200 and response.status_code < 300:
    print(f"Product {idx+1} created successfully!")
else:
    print(f"Failed to create product {idx+1}. Server responded with: {response.text}")

`