aigc 启动器 sd-webui-aki-v4 decode_base64_to_file
2024-01-09 18:34:38
下载地址:
decode_base64_to_file报错:
File "E:\BaiduNetdiskDownload\stable diffusion\sd-webui-aki-v4\extensions\sd-webui-controlnet\scripts\external_code.py", line 7, in <module>
from modules.api import api
File "E:\BaiduNetdiskDownload\stable diffusion\sd-webui-aki-v4\modules\api\api.py", line 9, in <module>
from gradio.processing_utils import decode_base64_to_file
ImportError: cannot import name 'decode_base64_to_file' from 'gradio.processing_utils'
报错2:
import gradio as gr
original_IOComponent_init = gr.components.IOComponent.__init__
4.*版本报错,?gradio-3.41.2-py3-none-any.whl 不报错
报错2:
File "E:\BaiduNetdiskDownload\stable diffusion\sd-webui-aki-v4\modules\api\models.py", line 96, in generate_model
DynamicModel.__config__.allow_population_by_field_name = True
File "D:\ProgramData\miniconda3\envs\pysd\lib\site-packages\pydantic\_internal\_model_construction.py", line 215, in __getattr__
raise AttributeError(item)
AttributeError: __config__
报错的gradio版本:
pip install gradio-3.41.2-py3-none-any.whl
sd-webui-aki-v4
from gradio.processing_utils import decode_base64_to_image
def decode_base64_to_image(encoding: str) -> Image.Image:
image_encoded = extract_base64_data(encoding)
img = Image.open(BytesIO(base64.b64decode(image_encoded)))
try:
if hasattr(ImageOps, "exif_transpose"):
img = ImageOps.exif_transpose(img)
except Exception:
log.warning(
"Failed to transpose image %s based on EXIF data.",
img,
exc_info=True,
)
return img
python 实现代码:
def decode_base64_to_image(encoding):
if encoding.startswith("data:image/"):
encoding = encoding.split(";")[1].split(",")[1]
try:
image = Image.open(BytesIO(base64.b64decode(encoding)))
return image
except Exception as err:
raise HTTPException(status_code=500, detail="Invalid encoded image")
def encode_pil_to_base64(image):
with io.BytesIO() as output_bytes:
if opts.samples_format.lower() == 'png':
use_metadata = False
metadata = PngImagePlugin.PngInfo()
for key, value in image.info.items():
if isinstance(key, str) and isinstance(value, str):
metadata.add_text(key, value)
use_metadata = True
image.save(output_bytes, format="PNG", pnginfo=(metadata if use_metadata else None), quality=opts.jpeg_quality)
elif opts.samples_format.lower() in ("jpg", "jpeg", "webp"):
parameters = image.info.get('parameters', None)
exif_bytes = piexif.dump({
"Exif": { piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(parameters or "", encoding="unicode") }
})
if opts.samples_format.lower() in ("jpg", "jpeg"):
image.save(output_bytes, format="JPEG", exif = exif_bytes, quality=opts.jpeg_quality)
else:
image.save(output_bytes, format="WEBP", exif = exif_bytes, quality=opts.jpeg_quality)
else:
raise HTTPException(status_code=500, detail="Invalid image format")
bytes_data = output_bytes.getvalue()
return base64.b64encode(bytes_data)
文章来源:https://blog.csdn.net/jacke121/article/details/135483624
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!