输出text
This commit is contained in:
		@@ -52,8 +52,17 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	// 图像中的文字提取
 | 
			
		||||
	// text := graphql.NewObject(graphql.ObjectConfig{})
 | 
			
		||||
	// 图像中的文字提取 [{"text": "角色选择", "confidence": 0.8484202027320862, "coordinate": [[666.0, 66.0], [908.0, 81.0], [903.0, 174.0], [661.0, 160.0]]}
 | 
			
		||||
	text := graphql.NewObject(graphql.ObjectConfig{
 | 
			
		||||
		Name: "Text",
 | 
			
		||||
		Fields: graphql.Fields{
 | 
			
		||||
			"text":       &graphql.Field{Type: graphql.String},
 | 
			
		||||
			"confidence": &graphql.Field{Type: graphql.Float},
 | 
			
		||||
			"coordinate": &graphql.Field{Type: &graphql.List{
 | 
			
		||||
				OfType: graphql.NewList(graphql.Float),
 | 
			
		||||
			}},
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	// 图像的可选字段
 | 
			
		||||
	image := graphql.NewObject(graphql.ObjectConfig{
 | 
			
		||||
@@ -67,7 +76,7 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
			
		||||
			"description":             &graphql.Field{Type: graphql.String},
 | 
			
		||||
			"tags":                    &graphql.Field{Type: graphql.String},
 | 
			
		||||
			"rank":                    &graphql.Field{Type: graphql.String},
 | 
			
		||||
			"text":                    &graphql.Field{Type: graphql.String},
 | 
			
		||||
			"text":                    &graphql.Field{Type: graphql.NewList(text)},
 | 
			
		||||
			"comment_num":             &graphql.Field{Type: graphql.Int},
 | 
			
		||||
			"article_category_top_id": &graphql.Field{Type: graphql.Int},
 | 
			
		||||
			"praise_count":            &graphql.Field{Type: graphql.Int},
 | 
			
		||||
@@ -302,6 +311,10 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
			
		||||
					return nil, err
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				// 打印带缩进格式化的JSON
 | 
			
		||||
				// str, _ := json.MarshalIndent(images, "", "    ")
 | 
			
		||||
				// fmt.Println("获取图像列表成功", string(str))
 | 
			
		||||
 | 
			
		||||
				// 获取用户信息(如果图像列表不为空且请求字段中包含user)
 | 
			
		||||
				if len(images) > 0 && strings.Contains(fields_str, "user_id") {
 | 
			
		||||
					// 取到所有的用户ID, 去除重复
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
package api
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -13,7 +14,6 @@ type Image struct {
 | 
			
		||||
	Description          string    `json:"description"             db:"description"`
 | 
			
		||||
	Tags                 string    `json:"tags"                    db:"tags"`
 | 
			
		||||
	Rank                 string    `json:"rank"                    db:"rank"`
 | 
			
		||||
	Text                 string    `json:"text"                    db:"text"`
 | 
			
		||||
	CommentNum           int       `json:"comment_num"             db:"comment_num"`
 | 
			
		||||
	ArticleCategoryTopId int       `json:"article_category_top_id" db:"article_category_top_id"`
 | 
			
		||||
	PraiseCount          int       `json:"praise_count"            db:"praise_count"`
 | 
			
		||||
@@ -24,6 +24,17 @@ type Image struct {
 | 
			
		||||
	Article              Article   `json:"article"                 db:"-"`
 | 
			
		||||
	CreateTime           time.Time `json:"create_time"             db:"create_time"`
 | 
			
		||||
	UpdateTime           time.Time `json:"update_time"             db:"update_time"`
 | 
			
		||||
	Text                 TextList  `json:"text"                    db:"text"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type TextList []struct {
 | 
			
		||||
	Text       string      `json:"text"`
 | 
			
		||||
	Confidence float64     `json:"confidence"`
 | 
			
		||||
	Coordinate [][]float64 `json:"coordinate"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *TextList) Scan(value interface{}) error {
 | 
			
		||||
	return json.Unmarshal(value.([]byte), a)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type User struct {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user