Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
coderai
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexlab
coderai
Commits
3995b98c
Commit
3995b98c
authored
Mar 14, 2026
by
Your Name
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: use stable-diffusion-cpp-python for image generation when available
parent
798f03eb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
0 deletions
+63
-0
coderai
coderai
+63
-0
No files found.
coderai
View file @
3995b98c
...
...
@@ -3132,6 +3132,7 @@ async def create_image_generation(request: ImageGenerationRequest):
Image generation endpoint (OpenAI-compatible).
Supports:
- Stable Diffusion via stable-diffusion-cpp-python (sd.cpp)
- Stable Diffusion XL (via local inference with diffusers)
- Other diffusers models
"""
...
...
@@ -3149,6 +3150,68 @@ async def create_image_generation(request: ImageGenerationRequest):
if model_to_use.startswith("image:"):
model_to_use = image_model
# First, try to use stable-diffusion-cpp-python (sd.cpp) if available
sd_model_key = f"image:{model_to_use}"
sd_model = multi_model_manager.get_model(sd_model_key)
if sd_model is not None:
# Check if it'
s
a
stable
-
diffusion
-
cpp
model
(
has
generate
method
from
sd
.
cpp
)
try
:
from
stable_diffusion_cpp
import
StableDiffusion
if
isinstance
(
sd_model
,
StableDiffusion
):
print
(
f
"Using stable-diffusion-cpp-python for image generation"
)
#
Use
sd
.
cpp
for
generation
#
Parse
size
width
,
height
=
512
,
512
if
request
.
size
:
parts
=
request
.
size
.
split
(
"x"
)
if
len
(
parts
)
==
2
:
try
:
width
=
int
(
parts
[
0
])
height
=
int
(
parts
[
1
])
except
ValueError
:
pass
#
Determine
number
of
steps
steps
=
request
.
steps
if
request
.
steps
else
4
#
Generate
images
using
sd
.
cpp
result
=
sd_model
.
generate
(
prompt
=
request
.
prompt
,
width
=
width
,
height
=
height
,
sample_steps
=
steps
,
n
=
request
.
n
if
request
.
n
else
1
,
)
#
Convert
results
to
response
format
images
=
[]
import
base64
import
io
from
PIL
import
Image
for
img
in
result
:
#
Convert
to
base64
buffered
=
io
.
BytesIO
()
if
isinstance
(
img
,
Image
.
Image
):
img
.
save
(
buffered
,
format
=
"PNG"
)
else
:
#
Might
be
numpy
array
Image
.
fromarray
(
img
).
save
(
buffered
,
format
=
"PNG"
)
img_bytes
=
buffered
.
getvalue
()
img_base64
=
base64
.
b64encode
(
img_bytes
).
decode
(
'utf-8'
)
images
.
append
({
"b64_json"
:
img_base64
})
return
{
"created"
:
int
(
time
.
time
()),
"data"
:
images
}
except
ImportError
:
pass
#
stable
-
diffusion
-
cpp
not
available
,
continue
to
diffusers
except
Exception
as
e
:
print
(
f
"sd.cpp generation error: {e}"
)
#
Continue
to
try
diffusers
#
Parse
size
(
e
.
g
.,
"1024x1024"
)
width
,
height
=
1024
,
1024
if
request
.
size
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment