首页 > 其他分享 >最新建筑应用(彩色版)

最新建筑应用(彩色版)

时间:2024-03-29 16:23:14浏览次数:17  
标签:name image 彩色版 最新 base file path os 建筑

import requests
import base64
import os
from PIL import Image
import io
import random

def encode_pil_to_base64(image):
    """
    Encode a PIL image to a Base64 string.
    """
    with io.BytesIO() as output_bytes:
        image.save(output_bytes, format="PNG")  # Using PNG format
        bytes_data = output_bytes.getvalue()
    return base64.b64encode(bytes_data).decode("utf-8")

def save_decoded_image(b64_image, base_path):
    """
    Save a Base64 encoded image to a file.
    Automatically adjusts the filename by adding a sequence number
    if a file with the same name already exists.
    """
    # Initialize the sequence number and the file path
    seq = 0
    output_path = base_path

    # Check if the file exists and adjust the filename if necessary
    while os.path.exists(output_path):
        seq += 1
        # Split the base path into the directory, basename, and extension
        dir_name, base_name = os.path.split(base_path)
        name, ext = os.path.splitext(base_name)
        # Construct a new filename with the sequence number
        output_path = os.path.join(dir_name, f"{name}({seq}){ext}")

    # Save the image to the new path
    with open(output_path, 'wb') as image_file:
        image_file.write(base64.b64decode(b64_image))
    print(f"Image saved to: {output_path}")

def main():
    # API URL
    url = "http://127.0.0.1:7860/sdapi/v1/txt2img"  # Update to img2img API if needed

    # Path to the folder containing reference images
    reference_image_dir = r"C:\Users\wujie1\Desktop\图片参考素材"

    # Find the latest file in the reference image folder
    latest_file_path = max(
        [os.path.join(reference_image_dir, f) for f in os.listdir(reference_image_dir) if os.path.isfile(os.path.join(reference_image_dir, f))],
        key=os.path.getmtime,
        default=None  # Default to None if the folder is empty
    )

    if latest_file_path is None:
        print("No image files found in the specified folder.")
        return

    # Open and encode the reference image to Base64
    with Image.open(latest_file_path) as img:
        encoded_image = encode_pil_to_base64(img)
        img_width, img_height = img.size  # Image dimensions

    # Construct the request payload
    data = {
        "prompt": "<lora:CWG_archisketch_v1:1>,Building,pre sketch,masterpiece,best quality,featuring markers,(3D:0.7)",
        "negative_prompt": "blurry, lower quality, glossy finish,insufficient contrast",
        "init_images": [encoded_image],  # Encoded image in a list
        "steps": 30,
        "width": img_width,
        "height": img_height,
        "seed": random.randint(1, 10000000),
        "alwayson_scripts": {
            "ControlNet": {
                "args": [
                     {
                         "enabled": "true",
                         "pixel_perfect": "true",
                         "module": "canny",
                         "model": "control_v11p_sd15_canny_fp16 [b18e0966]",
                         "weight": 1,
                         "image": encoded_image
                     },
                    {
                        "enabled": "true",
                        "pixel_perfect": "true",
                        "module": "depth",
                        "model": "control_v11f1p_sd15_depth_fp16 [4b72d323]",
                        "weight": 1,
                        "image": encoded_image
                    }
                ]
            }
        }
    }

    # Send the request and get the response
    response = requests.post(url, json=data)
    response_json = response.json()

    # Define the base path for saving the image (without sequence number)
    base_save_path = r"C:\Users\wujie1\Downloads\Building,pre sketch,masterpiece,best quality,featuring markers.png"
    save_decoded_image(response_json['images'][0], base_save_path)

if __name__ == '__main__':
    main()

 

标签:name,image,彩色版,最新,base,file,path,os,建筑
From: https://www.cnblogs.com/zly324/p/18104081

相关文章

  • 建筑转手稿,调完提示词
    importrequestsimportbase64importosfromPILimportImageimportioimportrandomdefencode_pil_to_base64(image):"""EncodeaPILimagetoaBase64string."""withio.BytesIO()asoutput_bytes:......
  • uniapp(全端兼容) - 最新移动端评论区讨论点赞回复功能,可发表文字或图片评论|点赞|回
    效果图在uniapp小程序/h5网页网站/安卓苹果app/nvue等(全平台完美兼容)开发中,实现评论区、讨论区功能详细教程,uniapp评论区用户可发布图片、视频、文字进行评论,其他用户可进行“无限级|盖楼评论区”,点赞评论、回复评论、删除评论(自动计算刷新,不影响布局),当评论大于n条时自......
  • 建筑转手稿
    importrequestsimportbase64importosfromPILimportImageimportioimportrandomdefencode_pil_to_base64(image):"""EncodeaPILimagetoaBase64string."""withio.BytesIO()asoutput_bytes:......
  • sd建筑工作流步骤1:文生图
    importrequestsimportbase64importosfromPILimportImageimportioimportjsonimportrandom#用于将图片编码为Base64格式的函数defencode_pil_to_base64(image):withio.BytesIO()asoutput_bytes:image.save(output_bytes,format="PNG")#注......
  • phpstorm激活最新2023 ,获永久使用权
    获取最新phpstorm:https://download-cdn.jetbrains.com.cn/webide/PhpStorm-2023.3.6.exe下载安装后输入有效激活码:X9MQ8ML8U7-eyJsaWNlbnNlSWQiOiJYOU1ROE1MOFU3IiwibGljZW5zZWVOYW1lIjoi5YWs5LyX5Y+377yaSmF2YeetkeWfuuacnyIsImFzc2lnbmVlTmFtZSI6IuS7heS+m+WoseS5kOa1i......
  • NVIDIA H200 创下 MLPerf LLM 最新推理记录
    NVIDIAH200TensorCoreGPU和NVIDIATensorRT-LLM创下MLPerfLLM最新推理记录生成式人工智能正在解锁新的计算应用程序,通过持续的模型创新来极大地增强人类的能力。生成式AI模型(包括大型语言模型(LLM))用于制作营销文案、编写计算机代码、渲染详细图像、创作音......
  • 2024最新最全Java和Go面经,面试了30多场,终于上岸了!
    ​>本文来自我们技术交流群群友的投稿,未经授权,禁止转载。原文链接:太难了,Java和Go,面试了30多场,终于上岸了!先听一下TA的故事2023年10月份我就做好了离职跳槽的准备,做了3年Java后端开发的我,对自己的技术能力还是很有底气的。之前虽不是一线大厂,也算是比较知名的中厂了。加上前公......
  • 智能汽车行业的发展最新趋势分析
    智能汽车行业的发展最新趋势主要体现在以下几个方面:智能化技术的深度应用:人工智能技术在汽车领域的应用将成为2024年智能化发展的重要趋势,通过深度学习、机器学习等技术的应用,汽车将具备更加智能的决策能力,提升驾驶安全性。此外,智能座舱和自动驾驶技术的进步也是关键趋势之一......
  • 最新AI创作系统/ChatGPT商业运营版网站程序源码,支持ai绘画(MJ),支持GPT4,实时语音识别输入
    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档文章目录目录文章目录前言一、系统更新日志二、功能总结前言最新AI创作系统/ChatGPT商业运营版网站程序源码,支持ai绘画(MJ),支持GPT4,实时语音识别输入,免费更新版本一、系统更新日志最新更......
  • 【Revit二次开发】创建建筑柱并旋转
    创建建筑柱参考:https://www.cnblogs.com/redcode/p/18100979建筑柱创建后再进行旋转,参考官方文档:https://help.autodesk.com/view/RVT/2014/ENU/?guid=GUID-B1C87D72-CAA5-4311-929C-CFC9B5480D24示例如下:ElementTransformUtils.RotateElement(doc,instance.Id,Rvt.Get......