fix: fixed bug for mj service pool config pointer

This commit is contained in:
RockYang 2023-12-15 22:52:57 +08:00
parent 58f3dd5336
commit 3bea8f9706
8 changed files with 77 additions and 53 deletions

View File

@ -10,10 +10,11 @@ import (
"chatplus/utils/resp" "chatplus/utils/resp"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/go-redis/redis/v8" "github.com/go-redis/redis/v8"
"gorm.io/gorm" "gorm.io/gorm"
"time"
) )
type SdJobHandler struct { type SdJobHandler struct {
@ -169,7 +170,7 @@ func (h *SdJobHandler) JobList(c *gin.Context) {
} }
if job.Progress == -1 { if job.Progress == -1 {
h.db.Delete(&model.MidJourneyJob{Id: job.Id}) h.db.Delete(&model.SdJob{Id: job.Id})
} }
if item.Progress < 100 { if item.Progress < 100 {

View File

@ -1,16 +1,24 @@
{ {
"data": [ "data": [
"task(owy5niy1sbbnlq0)", "task(vpu09bi42w01k5f)",
"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.", "A beautiful Chinese girl strolls along the beach",
"", "",
[], [],
30, 30,
"DPM++ 3M SDE Karras", "DPM++ 2M SDE Karras",
false,
false,
1, 1,
1, 1,
7, 7,
512, -1,
512, -1,
0,
0,
0,
false,
1024,
1024,
false, false,
0.7, 0.7,
2, 2,
@ -18,23 +26,11 @@
0, 0,
0, 0,
0, 0,
"Use same checkpoint",
"Use same sampler", "Use same sampler",
"", "",
"", "",
[], [],
"None", "None",
false,
"",
0.8,
-1,
false,
-1,
0,
0,
0,
null,
null,
null, null,
false, false,
false, false,
@ -58,22 +54,46 @@
false, false,
false, false,
0, 0,
null, "Not set",
null, 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, false,
null, "None",
null,
false,
null,
null, null,
false, false,
50, 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}",
"" "<p>A beautiful Chinese girl strolls along the beach<br>\nSteps: 30, Sampler: DPM++ 2M SDE Karras, CFG scale: 7, Seed: 291934632, Size: 1024x1024, Model hash: 2a4411ef93, Model: sdxlUnstableDiffusers_v7ElectricMind, Version: v1.5.2</p>",
"<p class='comments'></p><div class='performance'><p class='time'>Time taken: <wbr><span class='measurement'>11.2 sec.</span></p><p class='vram'><abbr title='Active: peak amount of video memory used during generation (excluding cached data)'>A</abbr>: <span class='measurement'>10.26 GB</span>, <wbr><abbr title='Reserved: total amout of video memory allocated by the Torch library '>R</abbr>: <span class='measurement'>13.34 GB</span>, <wbr><abbr title='System: peak amout of video memory allocated by all running programs, out of total capacity'>Sys</abbr>: <span class='measurement'>13.8/23.6904 GB</span> (58.1%)</p></div>"
], ],
"event_data": null, "event_data": null,
"fn_index": 316, "fn_index": 232,
"session_hash": "ttr8efgt63g" "session_hash": "sstp2i5ytoj"
} }

View File

@ -3,18 +3,19 @@ package mj
import ( import (
"chatplus/core/types" "chatplus/core/types"
"fmt" "fmt"
"github.com/imroc/req/v3"
"time" "time"
"github.com/imroc/req/v3"
) )
// MidJourney client // MidJourney client
type Client struct { type Client struct {
client *req.Client 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) client := req.C().SetTimeout(10 * time.Second)
// set proxy URL // set proxy URL
if proxy != "" { if proxy != "" {

View File

@ -5,6 +5,7 @@ import (
"chatplus/service/oss" "chatplus/service/oss"
"chatplus/store" "chatplus/store"
"fmt" "fmt"
"github.com/go-redis/redis/v8" "github.com/go-redis/redis/v8"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -24,7 +25,7 @@ func NewServicePool(db *gorm.DB, redisCli *redis.Client, manager *oss.UploaderMa
continue continue
} }
// create mj client // create mj client
client := NewClient(&config, appConfig.ProxyURL) client := NewClient(config, appConfig.ProxyURL)
name := fmt.Sprintf("MjService-%d", k) name := fmt.Sprintf("MjService-%d", k)
// create mj service // create mj service

View File

@ -5,6 +5,7 @@ import (
"chatplus/service/oss" "chatplus/service/oss"
"chatplus/store" "chatplus/store"
"fmt" "fmt"
"github.com/go-redis/redis/v8" "github.com/go-redis/redis/v8"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -25,7 +26,7 @@ func NewServicePool(db *gorm.DB, redisCli *redis.Client, manager *oss.UploaderMa
// create sd service // create sd service
name := fmt.Sprintf("StableDifffusion Service-%d", k) 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 // run sd service
go func() { go func() {
service.Run() service.Run()

View File

@ -8,20 +8,21 @@ import (
"chatplus/utils" "chatplus/utils"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/imroc/req/v3"
"gorm.io/gorm"
"io" "io"
"os" "os"
"strconv" "strconv"
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/imroc/req/v3"
"gorm.io/gorm"
) )
// SD 绘画服务 // SD 绘画服务
type Service struct { type Service struct {
httpClient *req.Client httpClient *req.Client
config *types.StableDiffusionConfig config types.StableDiffusionConfig
taskQueue *store.RedisQueue taskQueue *store.RedisQueue
db *gorm.DB db *gorm.DB
uploadManager *oss.UploaderManager uploadManager *oss.UploaderManager
@ -32,7 +33,7 @@ type Service struct {
taskTimeout int64 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{ return &Service{
name: name, name: name,
config: config, config: config,

View File

@ -33,13 +33,13 @@ var ParamKeys = map[string]int{
"steps": 4, "steps": 4,
"sampler": 5, "sampler": 5,
"face_fix": 6, // 面部修复 "face_fix": 6, // 面部修复
"cfg_scale": 8, "cfg_scale": 10,
"seed": 27, "seed": 11,
"height": 9, "height": 17,
"width": 10, "width": 18,
"hd_fix": 11, "hd_fix": 19,
"hd_redraw_rate": 12, //高清修复重绘幅度 "hd_redraw_rate": 20, //高清修复重绘幅度
"hd_scale": 13, // 高清修复放大倍数 "hd_scale": 21, // 高清修复放大倍数
"hd_scale_alg": 14, // 高清修复放大算法 "hd_scale_alg": 22, // 高清修复放大算法
"hd_sample_num": 15, // 高清修复采样次数 "hd_sample_num": 23, // 高清修复采样次数
} }

View File

@ -309,7 +309,7 @@
<div class="task-list-inner" :style="{ height: listBoxHeight + 'px' }"> <div class="task-list-inner" :style="{ height: listBoxHeight + 'px' }">
<h2>任务列表</h2> <h2>任务列表</h2>
<div class="running-job-list"> <div class="running-job-list">
<ItemList :items="runningJobs" v-if="runningJobs.length > 0" width="240"> <ItemList :items="runningJobs" v-if="runningJobs.length > 0" :width="240">
<template #default="scope"> <template #default="scope">
<div class="job-item"> <div class="job-item">
<div v-if="scope.item.progress > 0" class="job-item-inner"> <div v-if="scope.item.progress > 0" class="job-item-inner">
@ -350,7 +350,7 @@
</div> </div>
<h2>创作记录</h2> <h2>创作记录</h2>
<div class="finish-job-list"> <div class="finish-job-list">
<ItemList :items="finishedJobs" v-if="finishedJobs.length > 0" width="240" :gap="16"> <ItemList :items="finishedJobs" v-if="finishedJobs.length > 0" :width="240" :gap="16">
<template #default="scope"> <template #default="scope">
<div class="job-item animate" @click="showTask(scope.item)"> <div class="job-item animate" @click="showTask(scope.item)">
<el-image <el-image
@ -518,8 +518,7 @@ window.onresize = () => {
listBoxHeight.value = window.innerHeight - 40 listBoxHeight.value = window.innerHeight - 40
mjBoxHeight.value = window.innerHeight - 150 mjBoxHeight.value = window.innerHeight - 150
} }
const samplers = ["Euler a", "Euler", "DPM2 a Karras", "DPM++ 2S a Karras", "DPM++ 2M Karras", "DPM++ SDE Karras", "DPM2", "DPM2 a", "DPM++ 2S a", "DPM++ 2M", "DPM++ SDE", "DPM fast", "DPM adaptive", const samplers = ["Euler a", "Euler", "DPM++ 2S a Karras", "DPM++ 2M Karras", "DPM++ SDE Karras", "DPM++ 2M SDE Karras"]
"LMS Karras", "DPM2 Karras", "DDIM", "PLMS", "UniPC", "LMS", "Heun",]
const scaleAlg = ["Latent", "ESRGAN_4x", "R-ESRGAN 4x+", "SwinIR_4x", "LDSR"] const scaleAlg = ["Latent", "ESRGAN_4x", "R-ESRGAN 4x+", "SwinIR_4x", "LDSR"]
const params = ref({ const params = ref({
width: 1024, width: 1024,