提示词引导系数 (CFG Scale)
This commit is contained in:
		@@ -103,15 +103,15 @@ func ImagesPost(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
		// 通过模型推理生成图像, 为图像标记任务批次
 | 
			
		||||
		if match, _ := regexp.MatchString("application/json", r.Header.Get("Content-Type")); match {
 | 
			
		||||
			template := &struct {
 | 
			
		||||
				FromImage      int     `json:"from_image"`      // 来源图片(图生图时使用)
 | 
			
		||||
				Prompt         string  `json:"prompt"`          // 提示词
 | 
			
		||||
				NegativePrompt string  `json:"negative_prompt"` // 负面提示词
 | 
			
		||||
				Steps          int     `json:"steps"`           // 推理步数
 | 
			
		||||
				GuidanceScale  float32 `json:"guidance_scale"`  // 引导比例
 | 
			
		||||
				Scheduler      string  `json:"scheduler"`       // 调度器
 | 
			
		||||
				Seed           string  `json:"seed"`            // 随机种子(单张图生成时使用)
 | 
			
		||||
				NIter          int     `json:"n_iter"`          // 生成数量
 | 
			
		||||
				ModelID        int     `json:"model_id"`        // 模型ID
 | 
			
		||||
				FromImage      int    `json:"from_image"`      // 来源图片(图生图时使用)
 | 
			
		||||
				Prompt         string `json:"prompt"`          // 提示词
 | 
			
		||||
				NegativePrompt string `json:"negative_prompt"` // 负面提示词
 | 
			
		||||
				Steps          int    `json:"steps"`           // 推理步数
 | 
			
		||||
				CfgScale       int    `json:"cfg_scale"`       // 引导比例
 | 
			
		||||
				Scheduler      string `json:"scheduler"`       // 调度器
 | 
			
		||||
				Seed           string `json:"seed"`            // 随机种子(单张图生成时使用)
 | 
			
		||||
				NIter          int    `json:"n_iter"`          // 生成数量
 | 
			
		||||
				ModelID        int    `json:"model_id"`        // 模型ID
 | 
			
		||||
			}{}
 | 
			
		||||
			body, err := ioutil.ReadAll(r.Body)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
@@ -131,11 +131,11 @@ func ImagesPost(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
			if template.Steps <= 0 {
 | 
			
		||||
				template.Steps = 50
 | 
			
		||||
			}
 | 
			
		||||
			if template.GuidanceScale <= 0 {
 | 
			
		||||
				template.GuidanceScale = 1
 | 
			
		||||
			if template.CfgScale <= 0 {
 | 
			
		||||
				template.CfgScale = 1
 | 
			
		||||
			}
 | 
			
		||||
			if template.GuidanceScale > 20 {
 | 
			
		||||
				template.GuidanceScale = 20
 | 
			
		||||
			if template.CfgScale > 20 {
 | 
			
		||||
				template.CfgScale = 20
 | 
			
		||||
			}
 | 
			
		||||
			if template.Scheduler == "" {
 | 
			
		||||
				template.Scheduler = "DDIM"
 | 
			
		||||
@@ -166,7 +166,7 @@ func ImagesPost(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
				image.Prompt = template.Prompt
 | 
			
		||||
				image.NegativePrompt = template.NegativePrompt
 | 
			
		||||
				image.NumInferenceSteps = template.Steps
 | 
			
		||||
				image.GuidanceScale = template.GuidanceScale
 | 
			
		||||
				image.CfgScale = template.CfgScale
 | 
			
		||||
				image.Scheduler = template.Scheduler
 | 
			
		||||
				image.Seed = template.Seed
 | 
			
		||||
				image_list = append(image_list, image)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user