From 245cd3ee1ada8b818a8cfee6f96b751880ecd9a9 Mon Sep 17 00:00:00 2001 From: RockYang Date: Fri, 15 Dec 2023 22:52:57 +0800 Subject: [PATCH] fix: fixed bug for mj service pool config pointer --- api/handler/sd_handler.go | 5 ++- api/res/sd/text2img.json | 78 ++++++++++++++++++++++++--------------- api/service/mj/client.go | 7 ++-- api/service/mj/pool.go | 3 +- api/service/sd/pool.go | 3 +- api/service/sd/service.go | 9 +++-- api/service/sd/types.go | 18 ++++----- web/src/views/ImageSd.vue | 7 ++-- 8 files changed, 77 insertions(+), 53 deletions(-) diff --git a/api/handler/sd_handler.go b/api/handler/sd_handler.go index d81abfe4..3f73186e 100644 --- a/api/handler/sd_handler.go +++ b/api/handler/sd_handler.go @@ -10,10 +10,11 @@ import ( "chatplus/utils/resp" "encoding/base64" "fmt" + "time" + "github.com/gin-gonic/gin" "github.com/go-redis/redis/v8" "gorm.io/gorm" - "time" ) type SdJobHandler struct { @@ -169,7 +170,7 @@ func (h *SdJobHandler) JobList(c *gin.Context) { } if job.Progress == -1 { - h.db.Delete(&model.MidJourneyJob{Id: job.Id}) + h.db.Delete(&model.SdJob{Id: job.Id}) } if item.Progress < 100 { diff --git a/api/res/sd/text2img.json b/api/res/sd/text2img.json index c645454c..375c65c3 100644 --- a/api/res/sd/text2img.json +++ b/api/res/sd/text2img.json @@ -1,16 +1,24 @@ { "data": [ - "task(owy5niy1sbbnlq0)", - "A beautiful Chinese girl plays the guitar on the beach. She is dressed in a flowing dress that matches the colors of the sunset. With her eyes closed, she strums the guitar with passion and confidence, her fingers dancing gracefully on the strings. The painting employs a vibrant color palette, capturing the warmth of the setting sun blending with the serene hues of the ocean. The artist uses a combination of impressionistic and realistic brushstrokes to convey both the girl's delicate features and the dynamic movement of the waves. The rendering effect creates a dream-like atmosphere, as if the viewer is being transported to a magical realm where music and nature intertwine. The picture is bathed in a soft, golden light, casting a warm glow on the girl's face, illuminating her joy and connection to the music she creates.", + "task(vpu09bi42w01k5f)", + "A beautiful Chinese girl strolls along the beach", "", [], 30, - "DPM++ 3M SDE Karras", + "DPM++ 2M SDE Karras", + false, + false, 1, 1, 7, - 512, - 512, + -1, + -1, + 0, + 0, + 0, + false, + 1024, + 1024, false, 0.7, 2, @@ -18,23 +26,11 @@ 0, 0, 0, - "Use same checkpoint", "Use same sampler", "", "", [], "None", - false, - "", - 0.8, - -1, - false, - -1, - 0, - 0, - 0, - null, - null, null, false, false, @@ -58,22 +54,46 @@ false, false, 0, - null, - null, + "Not set", + true, + true, + "", + "", + "", + "", + "", + 1.3, + "Not set", + "Not set", + 1.3, + "Not set", + 1.3, + "Not set", + 1.3, + 1.3, + "Not set", + 1.3, + "Not set", + 1.3, + "Not set", + 1.3, + "Not set", + 1.3, + "Not set", + 1.3, + "Not set", false, - null, - null, - false, - null, + "None", null, false, 50, - [], - "", - "", - "" + [ + ], + "{\"prompt\": \"A beautiful Chinese girl strolls along the beach\", \"all_prompts\": [\"A beautiful Chinese girl strolls along the beach\"], \"negative_prompt\": \"\", \"all_negative_prompts\": [\"\"], \"seed\": 291934632, \"all_seeds\": [291934632], \"subseed\": 2486830045, \"all_subseeds\": [2486830045], \"subseed_strength\": 0, \"width\": 1024, \"height\": 1024, \"sampler_name\": \"DPM++ 2M SDE Karras\", \"cfg_scale\": 7, \"steps\": 30, \"batch_size\": 1, \"restore_faces\": false, \"face_restoration_model\": null, \"sd_model_hash\": \"2a4411ef93\", \"seed_resize_from_w\": 0, \"seed_resize_from_h\": 0, \"denoising_strength\": null, \"extra_generation_params\": {}, \"index_of_first_image\": 0, \"infotexts\": [\"A beautiful Chinese girl strolls along the beach\\nSteps: 30, Sampler: DPM++ 2M SDE Karras, CFG scale: 7, Seed: 291934632, Size: 1024x1024, Model hash: 2a4411ef93, Model: sdxlUnstableDiffusers_v7ElectricMind, Version: v1.5.2\"], \"styles\": [], \"job_timestamp\": \"20231215222321\", \"clip_skip\": 1, \"is_using_inpainting_conditioning\": false}", + "

A beautiful Chinese girl strolls along the beach
\nSteps: 30, Sampler: DPM++ 2M SDE Karras, CFG scale: 7, Seed: 291934632, Size: 1024x1024, Model hash: 2a4411ef93, Model: sdxlUnstableDiffusers_v7ElectricMind, Version: v1.5.2

", + "

Time taken: 11.2 sec.

A: 10.26 GB, R: 13.34 GB, Sys: 13.8/23.6904 GB (58.1%)

" ], "event_data": null, - "fn_index": 316, - "session_hash": "ttr8efgt63g" + "fn_index": 232, + "session_hash": "sstp2i5ytoj" } \ No newline at end of file diff --git a/api/service/mj/client.go b/api/service/mj/client.go index 584e93bd..6078b708 100644 --- a/api/service/mj/client.go +++ b/api/service/mj/client.go @@ -3,18 +3,19 @@ package mj import ( "chatplus/core/types" "fmt" - "github.com/imroc/req/v3" "time" + + "github.com/imroc/req/v3" ) // MidJourney client type Client struct { client *req.Client - config *types.MidJourneyConfig + config types.MidJourneyConfig } -func NewClient(config *types.MidJourneyConfig, proxy string) *Client { +func NewClient(config types.MidJourneyConfig, proxy string) *Client { client := req.C().SetTimeout(10 * time.Second) // set proxy URL if proxy != "" { diff --git a/api/service/mj/pool.go b/api/service/mj/pool.go index efcd853e..4d99b41c 100644 --- a/api/service/mj/pool.go +++ b/api/service/mj/pool.go @@ -5,6 +5,7 @@ import ( "chatplus/service/oss" "chatplus/store" "fmt" + "github.com/go-redis/redis/v8" "gorm.io/gorm" ) @@ -24,7 +25,7 @@ func NewServicePool(db *gorm.DB, redisCli *redis.Client, manager *oss.UploaderMa continue } // create mj client - client := NewClient(&config, appConfig.ProxyURL) + client := NewClient(config, appConfig.ProxyURL) name := fmt.Sprintf("MjService-%d", k) // create mj service diff --git a/api/service/sd/pool.go b/api/service/sd/pool.go index 4a817983..1bd4a065 100644 --- a/api/service/sd/pool.go +++ b/api/service/sd/pool.go @@ -5,6 +5,7 @@ import ( "chatplus/service/oss" "chatplus/store" "fmt" + "github.com/go-redis/redis/v8" "gorm.io/gorm" ) @@ -25,7 +26,7 @@ func NewServicePool(db *gorm.DB, redisCli *redis.Client, manager *oss.UploaderMa // create sd service name := fmt.Sprintf("StableDifffusion Service-%d", k) - service := NewService(name, 4, 600, &config, queue, db, manager) + service := NewService(name, 4, 600, config, queue, db, manager) // run sd service go func() { service.Run() diff --git a/api/service/sd/service.go b/api/service/sd/service.go index 0a1881e2..31a1e0cc 100644 --- a/api/service/sd/service.go +++ b/api/service/sd/service.go @@ -8,20 +8,21 @@ import ( "chatplus/utils" "encoding/json" "fmt" - "github.com/imroc/req/v3" - "gorm.io/gorm" "io" "os" "strconv" "sync/atomic" "time" + + "github.com/imroc/req/v3" + "gorm.io/gorm" ) // SD 绘画服务 type Service struct { httpClient *req.Client - config *types.StableDiffusionConfig + config types.StableDiffusionConfig taskQueue *store.RedisQueue db *gorm.DB uploadManager *oss.UploaderManager @@ -32,7 +33,7 @@ type Service struct { taskTimeout int64 } -func NewService(name string, maxTaskNum int32, timeout int64, config *types.StableDiffusionConfig, queue *store.RedisQueue, db *gorm.DB, manager *oss.UploaderManager) *Service { +func NewService(name string, maxTaskNum int32, timeout int64, config types.StableDiffusionConfig, queue *store.RedisQueue, db *gorm.DB, manager *oss.UploaderManager) *Service { return &Service{ name: name, config: config, diff --git a/api/service/sd/types.go b/api/service/sd/types.go index 5dfb02ae..08e50127 100644 --- a/api/service/sd/types.go +++ b/api/service/sd/types.go @@ -33,13 +33,13 @@ var ParamKeys = map[string]int{ "steps": 4, "sampler": 5, "face_fix": 6, // 面部修复 - "cfg_scale": 8, - "seed": 27, - "height": 9, - "width": 10, - "hd_fix": 11, - "hd_redraw_rate": 12, //高清修复重绘幅度 - "hd_scale": 13, // 高清修复放大倍数 - "hd_scale_alg": 14, // 高清修复放大算法 - "hd_sample_num": 15, // 高清修复采样次数 + "cfg_scale": 10, + "seed": 11, + "height": 17, + "width": 18, + "hd_fix": 19, + "hd_redraw_rate": 20, //高清修复重绘幅度 + "hd_scale": 21, // 高清修复放大倍数 + "hd_scale_alg": 22, // 高清修复放大算法 + "hd_sample_num": 23, // 高清修复采样次数 } diff --git a/web/src/views/ImageSd.vue b/web/src/views/ImageSd.vue index 18cfac2a..761f01bb 100644 --- a/web/src/views/ImageSd.vue +++ b/web/src/views/ImageSd.vue @@ -309,7 +309,7 @@

任务列表

- +