Skip to content

Commit 439cbca

Browse files
committed
first commit
0 parents  commit 439cbca

14 files changed

+1874
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.vscode
2+
.mypy_cache
3+
build
4+
dist
5+
__pycache__

.gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "sd_cpp_lib/pybind11"]
2+
path = sd_cpp_lib/pybind11
3+
url = https://github.com/pybind/pybind11.git
4+
[submodule "sd_cpp_lib/stable-diffusion.cpp"]
5+
path = sd_cpp_lib/stable-diffusion.cpp
6+
url = https://github.com/leejet/stable-diffusion.cpp.git

CMakeLists.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required(VERSION 3.21)
2+
3+
project(stable_diffusion_cpp)
4+
5+
add_subdirectory(sd_cpp_lib)
6+
7+
install(
8+
TARGETS sd_cpp_lib
9+
LIBRARY DESTINATION ${SKBUILD_PLATLIB_DIR}/stable_diffusion_cpp
10+
RUNTIME DESTINATION ${SKBUILD_PLATLIB_DIR}/stable_diffusion_cpp
11+
ARCHIVE DESTINATION ${SKBUILD_PLATLIB_DIR}/stable_diffusion_cpp
12+
FRAMEWORK DESTINATION ${SKBUILD_PLATLIB_DIR}/stable_diffusion_cpp
13+
RESOURCE DESTINATION ${SKBUILD_PLATLIB_DIR}/stable_diffusion_cpp)

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# stable_diffusion_cpp_py
2+
3+
python bind for stable_diffusion_cpp by pybind11
4+
5+
## install
6+
7+
- if you use nvidia gpu, execute `CMAKE_ARGS="-DSD_CUBLAS=on" pip install git+https://github.com/null-define/stable-diffusion-cpp-py` install
8+
- if you use amd gpu, execute `CC=/opt/rocm/llvm/bin/clang CXX=/opt/rocm/llvm/bin/clang++ CMAKE_ARGS="-DSD_HIPBLAS=ON -DAMDGPU_TARGETS=gfx1100" pip install git+https://github.com/null-define/stable-diffusion-cpp-py` install
9+
10+
11+
## References
12+
- [stable-diffusion.cpp](https://github.com/leejet/stable-diffusion.cpp)
13+
- [pybind11](https://github.com/pybind/pybind11)

pyproject.toml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
[build-system]
2+
requires = ["scikit-build-core[pyproject]>=0.5.1"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "stable_diffusion_cpp_py"
7+
dynamic = ["version"]
8+
description = "Python bindings for the stable_diffusion.cpp library"
9+
readme = "README.md"
10+
license = { text = "MIT" }
11+
authors = [
12+
{ name = "Qiang", email = "[email protected]" },
13+
]
14+
dependencies = [
15+
"typing-extensions>=4.5.0",
16+
"numpy>=1.20.0",
17+
"diskcache>=5.6.1",
18+
"jinja2>=2.11.3",
19+
]
20+
requires-python = ">=3.8"
21+
classifiers = [
22+
"Programming Language :: Python :: 3",
23+
"Programming Language :: Python :: 3.8",
24+
"Programming Language :: Python :: 3.9",
25+
"Programming Language :: Python :: 3.10",
26+
"Programming Language :: Python :: 3.11",
27+
"Programming Language :: Python :: 3.12",
28+
]
29+
30+
31+
[project.optional-dependencies]
32+
33+
test = [
34+
"pytest>=7.4.0",
35+
"httpx>=0.24.1",
36+
"scipy>=1.10",
37+
]
38+
dev = [
39+
"black>=23.3.0",
40+
"twine>=4.0.2",
41+
"mkdocs>=1.4.3",
42+
"mkdocstrings[python]>=0.22.0",
43+
"mkdocs-material>=9.1.18",
44+
"pytest>=7.4.0",
45+
]
46+
all = [
47+
"stable_diffusion_cpp[test,dev]",
48+
]
49+
50+
[tool.scikit-build]
51+
wheel.packages = ["stable_diffusion_cpp"]
52+
cmake.verbose = true
53+
cmake.minimum-version = "3.21"
54+
minimum-version = "0.5.1"
55+
56+
[tool.scikit-build.metadata.version]
57+
provider = "scikit_build_core.metadata.regex"
58+
input = "stable_diffusion_cpp/__init__.py"
59+
60+
[project.urls]
61+
62+
[tool.pytest.ini_options]
63+
testpaths = "tests"

sample/cli.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from stable_diffusion_cpp import StableDiffusion
2+
from PIL import Image
3+
import numpy as np
4+
5+
6+
good_words = [
7+
"best quality",
8+
"fantasy",
9+
"highly detailed 8k UHD",
10+
"masterpiece",
11+
]
12+
13+
sd = StableDiffusion(
14+
model_path="",
15+
esrgan_path="",
16+
)
17+
img = sd.txt_to_img(prompt=good_words + [""])
18+
img = sd.upscale_img(img, 4)
19+
im = Image.fromarray(np.array(img))
20+
im.save("img.jpg")

sd_cpp_lib/.clang-format

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Use the Google style in this project.
2+
BasedOnStyle: Google
3+
4+
# Some folks prefer to write "int& foo" while others prefer "int &foo". The
5+
# Google Style Guide only asks for consistency within a project, we chose
6+
# "int& foo" for this project:
7+
DerivePointerAlignment: false
8+
PointerAlignment: Left
9+
10+
# The Google Style Guide only asks for consistency w.r.t. "east const" vs.
11+
# "const west" alignment of cv-qualifiers. In this project we use "east const".
12+
QualifierAlignment: Right
13+
14+
IncludeBlocks: Merge
15+
IncludeCategories:
16+
- Regex: '^\"google/cloud/internal/disable_deprecation_warnings.inc\"$'
17+
Priority: -1
18+
# System and C-language headers should go last. These expressions may miss a few
19+
# cases, we can always add more. Or we can conservative
20+
- Regex: '^<[A-Za-z0-9_]*\.h>$'
21+
Priority: 10000
22+
- Regex: '^<sys/[A-Za-z0-9_]*\.h>$'
23+
Priority: 10000
24+
# Matches common headers first, but sorts them after project includes
25+
- Regex: '^\"google/cloud/(internal/|grpc_utils/|testing_util/|[^/]+\.h)'
26+
Priority: 1000
27+
- Regex: '^\"google/cloud/' # project includes should sort first
28+
Priority: 500
29+
- Regex: '^\"generator/' # project includes should sort first
30+
Priority: 500
31+
- Regex: '^\"generator/internal/' # project internals second
32+
Priority: 1000
33+
- Regex: '^\"generator/testing/' # testing helpers third
34+
Priority: 1100
35+
- Regex: '^\"' # And then includes from other projects or the system
36+
Priority: 1500
37+
- Regex: '^<grpc/'
38+
Priority: 2000
39+
- Regex: '^<google/*'
40+
Priority: 3000
41+
- Regex: '^<.*/.*'
42+
Priority: 4000
43+
- Regex: '^<.*.hpp>'
44+
Priority: 4000
45+
- Regex: '^<[^/]*>'
46+
Priority: 5000
47+
48+
# Format raw string literals with a `pb` or `proto` tag as proto.
49+
RawStringFormats:
50+
- Language: TextProto
51+
Delimiters:
52+
- 'pb'
53+
- 'proto'
54+
BasedOnStyle: Google
55+
56+
CommentPragmas: '(@copydoc|@copybrief|@see|@overload|@snippet)'

sd_cpp_lib/CMakeLists.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cmake_minimum_required(VERSION 3.5...3.26)
2+
set(CMAKE_CXX_STANDARD 17)
3+
4+
project(sd_cpp_lib LANGUAGES CXX)
5+
set(CMAKE_EXPORT_COMPILE_COMMANDS true)
6+
7+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC")
8+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -fPIC")
9+
10+
find_package(
11+
Python
12+
COMPONENTS Interpreter Development
13+
REQUIRED)
14+
15+
add_subdirectory(./pybind11 EXCLUDE_FROM_ALL)
16+
add_subdirectory(./stable-diffusion.cpp EXCLUDE_FROM_ALL)
17+
18+
set(TARGET sd_cpp_lib)
19+
pybind11_add_module(${TARGET} sd_cpp_lib.cc)
20+
target_link_libraries(${TARGET} PRIVATE stable-diffusion)
21+
22+

0 commit comments

Comments
 (0)