说起 discoart 可能大部分都不太了解。
但是,说到艺术库,可能你就有些印象了。
这里,我也引用官网对discoart的解析,让你对它有个初步的了解,如下:
DiscoArt is an elegant way of creating compelling Disco Diffusion[*] artworks for generative artists, AI enthusiasts and hard-core developers.
DiscoArt has a modern & professional API with a beautiful codebase, ensuring high usability and maintainability. It introduces handy features such as result recovery and persistence, gRPC/HTTP serving w/o TLS, post-analysis, easing the integration to larger cross-modal or multi-modal applications.
这里,我也简答的用汉语描述一下,即:
DiscoArt是一种优雅的方式,可以为生成艺术家,AI爱好者和铁杆开发人员创建引人注目的Disco Diffusion艺术品。
DiscoArt拥有现代和专业的API,具有漂亮的代码库,确保了高可用性和可维护性。它引入了方便的功能,例如结果恢复和持久性,没有TLS的gRPC / HTTP服务,后期分析,简化与更大的跨模态或多模态应用程序的集成。
简答一句话概括:DiscoArt就是为了艺术而生的。
涉及到第三方库,肯定就需要安装
老规矩,pip 安装
- pip install discoart
-
然后就是等待着安装。
其它安装方式,直接看这两篇:
安装的样子,如下:
这里提示一下:
这里直接使用discoart的 create方法即可
代码示例:
- # -*- coding:utf-8 -*-
- # @Time : 2023-02-12
- # @Author : Carl_DJ
- '''
- 实现功能:
- 使用默认参数创建图片
- '''
-
- from discoart import create
-
- ca = create()
-
-
效果展示
- # -*- coding:utf-8 -*-
- # @Time : 2023-02-12
- # @Author : Carl_DJ
- '''
- 实现功能:
- 设置参数创建图片
- '''
-
- from discoart import create
-
- #设置参数
- ca = create(
- text_prompts='A painting of sea cliffs in a tumultuous storm, Trending on ArtStation.',
- init_image='https://d2vyhzeko0lke5.cloudfront.net/xxxx7e77b72f0.png',
- skip_steps=100,
- )
-
-
效果展示
如果你忘记参数,也没关系,直接用cheatsheet查询即可
代码展示
- # -*- coding:utf-8 -*-
- # @Time : 2023-02-12
- # @Author : Carl_DJ
- '''
- 实现功能:
- 查看设置参数
- '''
-
- from discoart import cheatsheet
-
- #设置参数
- sha = cheatsheet()
-
如果要查看文档配置, 可以使用show_config:
代码展示
- # -*- coding:utf-8 -*-
- # @Time : 2023-02-12
- # @Author : Carl_DJ
- '''
- 实现功能:
- 查看文档配置
- '''
-
- from discorat import show_config
-
- # 展示第一个项目运行的配置
- show_config(da)
-
- # 参考第四个项目的运行配置
- show_config(da[3])
-
- #查看discoartID
- show_config('discoart-xxxxfbf288')
-
如果要保存文档配置, 可以使用save_config:
代码展示
- # -*- coding:utf-8 -*-
- # @Time : 2023-02-12
- # @Author : Carl_DJ
- '''
- 实现功能:
- 保存文档配置
- '''
-
- from discoart import save_config
-
- #保存第一次运行的配置
- save_config(da, 'my.yml')
-
- #保存第四次运行的配置
- save_config(da[3], 'my.yml')
-
有了查看和保存,当然也可以直接加载配置文件了, 这里,使用load_config即可
代码示例
- # -*- coding:utf-8 -*-
- # @Time : 2023-02-12
- # @Author : Carl_DJ
- '''
- 实现功能:
- 加载文档配置
- '''
-
- from discoart import create, load_config
-
- #加载配置文件
- config = load_config('my.yml')
-
- create(**config)
-
-
为了便于后期的管理使用,同样可以直接导出配置文件为SVG映像,使用save_config_svg方法:
代码示例
- # -*- coding:utf-8 -*-
- # @Time : 2023-02-12
- # @Author : Carl_DJ
- '''
- 实现功能:
- 导出配置文件为SVG映像
- '''
-
- from discoart.config import save_config_svg
-
- #直接保存为svg映像
- save_config_svg(da)
-
-
这里也展示一下, 保存的svg映像
更神奇的功能,就是可以直接从配置中生成可运行的Python代码,使用export_python方法:
代码示例
- # -*- coding:utf-8 -*-
- # @Time : 2023-02-12
- # @Author : Carl_DJ
- '''
- 实现功能:
- 生成可运行的Python代码
- '''
-
- from discoart.config import export_python
-
- export_python(da)
-
-
代码示例
- # -*- coding:utf-8 -*-
- # @Time : 2023-02-12
- # @Author : Carl_DJ
- '''
- 实现功能:
- 调用DocumentArray作为初始状态,运行
- '''
-
- from discoart import create
- from docarray import DocumentArray
-
- da = DocumentArray.pull('discoart-32xxx')
-
- create(
- init_document=da[0],
- cut_ic_pow=0.5,
- tv_scale=600,
- cut_overview='[12]*1000',
- cut_innercut='[12]*1000',
- use_secondary_model=False,
- )
-
-
- # -*- coding:utf-8 -*-
- # @Time : 2023-02-12
- # @Author : Carl_DJ
- '''
- 实现功能:
- 从已有的 DocArray ID 初始化
- '''
-
- from discoart import create
-
- create(init_document='discoart-320xxxx')
-
-
看到这里, Doscart库的介绍就完成了。
按照流程, 我们来回顾一下今天都分享了啥内容:
你看, Doscoart也没有想想的那么难嘛, 常用的功能,也就差不多这么多。
所以, 只要我们把一个库从头到尾的捋一遍, 其实是很容易掌握的。