2023-07-15 01:19:43 +02:00
|
|
|
package backend
|
|
|
|
|
|
|
|
import (
|
|
|
|
config "github.com/go-skynet/LocalAI/api/config"
|
|
|
|
"github.com/go-skynet/LocalAI/api/options"
|
2023-07-15 01:19:43 +02:00
|
|
|
"github.com/go-skynet/LocalAI/pkg/grpc/proto"
|
2023-07-15 01:19:43 +02:00
|
|
|
model "github.com/go-skynet/LocalAI/pkg/model"
|
|
|
|
)
|
|
|
|
|
2023-08-17 23:38:59 +02:00
|
|
|
func ImageGeneration(height, width, mode, step, seed int, positive_prompt, negative_prompt, src, dst string, loader *model.ModelLoader, c config.Config, o *options.Option) (func() error, error) {
|
2023-07-15 01:19:43 +02:00
|
|
|
|
2023-08-19 01:49:33 +02:00
|
|
|
opts := modelOpts(c, o, []model.Option{
|
2023-07-15 01:19:43 +02:00
|
|
|
model.WithBackendString(c.Backend),
|
|
|
|
model.WithAssetDir(o.AssetsDestination),
|
|
|
|
model.WithThreads(uint32(c.Threads)),
|
2023-07-15 01:19:43 +02:00
|
|
|
model.WithContext(o.Context),
|
2023-08-09 08:38:51 +02:00
|
|
|
model.WithModel(c.Model),
|
|
|
|
model.WithLoadGRPCLoadModelOpts(&proto.ModelOptions{
|
|
|
|
CUDA: c.Diffusers.CUDA,
|
|
|
|
SchedulerType: c.Diffusers.SchedulerType,
|
|
|
|
PipelineType: c.Diffusers.PipelineType,
|
2023-08-16 01:11:42 +02:00
|
|
|
CFGScale: c.Diffusers.CFGScale,
|
2023-08-27 10:11:16 +02:00
|
|
|
LoraAdapter: c.LoraAdapter,
|
|
|
|
LoraBase: c.LoraBase,
|
2023-08-17 23:38:59 +02:00
|
|
|
IMG2IMG: c.Diffusers.IMG2IMG,
|
|
|
|
CLIPModel: c.Diffusers.ClipModel,
|
|
|
|
CLIPSubfolder: c.Diffusers.ClipSubFolder,
|
|
|
|
CLIPSkip: int32(c.Diffusers.ClipSkip),
|
2023-08-09 08:38:51 +02:00
|
|
|
}),
|
2023-08-19 01:49:33 +02:00
|
|
|
})
|
2023-07-20 22:10:12 +02:00
|
|
|
|
|
|
|
inferenceModel, err := loader.BackendLoader(
|
|
|
|
opts...,
|
2023-07-15 01:19:43 +02:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-07-15 01:19:43 +02:00
|
|
|
fn := func() error {
|
|
|
|
_, err := inferenceModel.GenerateImage(
|
|
|
|
o.Context,
|
|
|
|
&proto.GenerateImageRequest{
|
2023-08-14 23:12:00 +02:00
|
|
|
Height: int32(height),
|
|
|
|
Width: int32(width),
|
|
|
|
Mode: int32(mode),
|
|
|
|
Step: int32(step),
|
|
|
|
Seed: int32(seed),
|
2023-08-17 23:38:59 +02:00
|
|
|
CLIPSkip: int32(c.Diffusers.ClipSkip),
|
2023-08-14 23:12:00 +02:00
|
|
|
PositivePrompt: positive_prompt,
|
|
|
|
NegativePrompt: negative_prompt,
|
|
|
|
Dst: dst,
|
2023-08-17 23:38:59 +02:00
|
|
|
Src: src,
|
2023-08-14 23:12:00 +02:00
|
|
|
EnableParameters: c.Diffusers.EnableParameters,
|
2023-07-15 01:19:43 +02:00
|
|
|
})
|
|
|
|
return err
|
2023-07-15 01:19:43 +02:00
|
|
|
}
|
|
|
|
|
2023-08-18 15:23:14 -04:00
|
|
|
return fn, nil
|
2023-07-15 01:19:43 +02:00
|
|
|
}
|