Compare commits
2 Commits
b656065b43
...
e795ac5d9a
| Author | SHA1 | Date | |
|---|---|---|---|
| e795ac5d9a | |||
| 0504a4643c |
@@ -30,7 +30,7 @@ type Image struct {
|
|||||||
NumInferenceSteps int `json:"num_inference_steps"` // 推理步数(minimum: 1; maximum: 500)
|
NumInferenceSteps int `json:"num_inference_steps"` // 推理步数(minimum: 1; maximum: 500)
|
||||||
GuidanceScale float32 `json:"guidance_scale"` // 引导比例(minimum: 1; maximum: 20)
|
GuidanceScale float32 `json:"guidance_scale"` // 引导比例(minimum: 1; maximum: 20)
|
||||||
Scheduler string `json:"scheduler"` // 调度器(DDIM|K_EULER|DPMSolverMultistep|K_EULER_ANCESTRAL|PNDM|KLMS)
|
Scheduler string `json:"scheduler"` // 调度器(DDIM|K_EULER|DPMSolverMultistep|K_EULER_ANCESTRAL|PNDM|KLMS)
|
||||||
Seed int `json:"seed"` // 随机种子(minimum: 0; maximum: 2147483647)
|
Seed string `json:"seed"` // 随机种子(minimum: 0; maximum: 2147483647)
|
||||||
FromImage int `json:"from_image"` // 来源图片(如果是从图片生成的, 则记录来源图片的ID)
|
FromImage int `json:"from_image"` // 来源图片(如果是从图片生成的, 则记录来源图片的ID)
|
||||||
Task string `json:"task"` // 任务编号(uuid)
|
Task string `json:"task"` // 任务编号(uuid)
|
||||||
Status string `json:"status"` // 任务状态(queued|running|finished|failed)
|
Status string `json:"status"` // 任务状态(queued|running|finished|failed)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
_ "image/gif"
|
_ "image/gif"
|
||||||
_ "image/jpeg"
|
_ "image/jpeg"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
@@ -82,9 +83,7 @@ func ImagesPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
models.AccountRead(w, r, func(account *models.Account) {
|
models.AccountRead(w, r, func(account *models.Account) {
|
||||||
|
|
||||||
// 通过模型推理生成图像, 为图像标记任务批次
|
// 通过模型推理生成图像, 为图像标记任务批次
|
||||||
if r.Header.Get("Content-Type") == "application/json" || r.Header.Get("Content-Type") == "application/json; charset=utf-8" {
|
if match, _ := regexp.MatchString("application/json", r.Header.Get("Content-Type")); match {
|
||||||
|
|
||||||
// 接收模板参数
|
|
||||||
template := &struct {
|
template := &struct {
|
||||||
FromImage int `json:"from_image"` // 来源图片(图生图时使用)
|
FromImage int `json:"from_image"` // 来源图片(图生图时使用)
|
||||||
Prompt string `json:"prompt"` // 提示词
|
Prompt string `json:"prompt"` // 提示词
|
||||||
@@ -92,7 +91,7 @@ func ImagesPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
NumInferenceSteps int `json:"num_inference_steps"` // 推理步数
|
NumInferenceSteps int `json:"num_inference_steps"` // 推理步数
|
||||||
GuidanceScale float32 `json:"guidance_scale"` // 引导比例
|
GuidanceScale float32 `json:"guidance_scale"` // 引导比例
|
||||||
Scheduler string `json:"scheduler"` // 调度器
|
Scheduler string `json:"scheduler"` // 调度器
|
||||||
Seed int `json:"seed"` // 随机种子(单张图生成时使用)
|
Seed string `json:"seed"` // 随机种子(单张图生成时使用)
|
||||||
Number int `json:"number"` // 生成数量
|
Number int `json:"number"` // 生成数量
|
||||||
}{}
|
}{}
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
@@ -106,6 +105,20 @@ func ImagesPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 输入检查
|
||||||
|
if template.Number <= 0 {
|
||||||
|
template.Number = 1
|
||||||
|
}
|
||||||
|
if template.NumInferenceSteps <= 0 {
|
||||||
|
template.NumInferenceSteps = 20
|
||||||
|
}
|
||||||
|
if template.GuidanceScale <= 0 {
|
||||||
|
template.GuidanceScale = 1
|
||||||
|
}
|
||||||
|
if template.GuidanceScale > 20 {
|
||||||
|
template.GuidanceScale = 20
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: 创建任务获得任务编号, 多张图时期望可以流式推理
|
// TODO: 创建任务获得任务编号, 多张图时期望可以流式推理
|
||||||
task := uuid.New().String()
|
task := uuid.New().String()
|
||||||
|
|
||||||
@@ -134,6 +147,7 @@ func ImagesPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
json.NewEncoder(w).Encode(image_list)
|
json.NewEncoder(w).Encode(image_list)
|
||||||
|
//w.Write(utils.ToJSON({"task": task, "list": image_list}))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user