.
This commit is contained in:
parent
6b40606081
commit
789a89f795
Binary file not shown.
@ -5,7 +5,6 @@ go 1.23.2
|
|||||||
require (
|
require (
|
||||||
github.com/PuerkitoBio/goquery v1.10.2
|
github.com/PuerkitoBio/goquery v1.10.2
|
||||||
github.com/gorilla/websocket v1.5.3
|
github.com/gorilla/websocket v1.5.3
|
||||||
github.com/sashabaranov/go-openai v1.38.0
|
|
||||||
github.com/ssgo/httpclient v1.7.8
|
github.com/ssgo/httpclient v1.7.8
|
||||||
github.com/ssgo/log v1.7.7
|
github.com/ssgo/log v1.7.7
|
||||||
github.com/ssgo/s v1.7.22
|
github.com/ssgo/s v1.7.22
|
||||||
@ -17,7 +16,6 @@ require (
|
|||||||
github.com/go-ole/go-ole v1.3.0 // indirect
|
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||||
github.com/gomodule/redigo v1.9.2 // indirect
|
github.com/gomodule/redigo v1.9.2 // indirect
|
||||||
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect
|
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect
|
||||||
github.com/otiai10/gosseract/v2 v2.4.1 // indirect
|
|
||||||
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
|
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
|
||||||
github.com/shirou/gopsutil/v3 v3.24.5 // indirect
|
github.com/shirou/gopsutil/v3 v3.24.5 // indirect
|
||||||
github.com/shoenig/go-m1cpu v0.1.6 // indirect
|
github.com/shoenig/go-m1cpu v0.1.6 // indirect
|
||||||
|
48
go/image.go
48
go/image.go
@ -1,15 +1,20 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/otiai10/gosseract/v2"
|
"github.com/ssgo/httpclient"
|
||||||
"github.com/ssgo/log"
|
"github.com/ssgo/log"
|
||||||
"github.com/ssgo/u"
|
"github.com/ssgo/u"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkImg(imgStr string) error {
|
func checkImg(imgStr string) error {
|
||||||
text := ocrImage(u.UnBase64(strings.Split(imgStr, "base64,")[1]))
|
text := OCR(u.UnBase64(strings.Split(imgStr, "base64,")[1]))
|
||||||
|
if text == "" {
|
||||||
|
return errors.New("text is empty")
|
||||||
|
}
|
||||||
log.DefaultLogger.Info("checkImg", "imgStrLen", len(imgStr), "imgLen", len(u.UnBase64(strings.Split(imgStr, "base64,")[1])), "text", text)
|
log.DefaultLogger.Info("checkImg", "imgStrLen", len(imgStr), "imgLen", len(u.UnBase64(strings.Split(imgStr, "base64,")[1])), "text", text)
|
||||||
score, err := parseRiskScore(ask(buildImgDetectionPrompt(text)))
|
score, err := parseRiskScore(ask(buildImgDetectionPrompt(text)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -31,24 +36,35 @@ func checkImg(imgStr string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ocrImage(image []byte) string {
|
func OCR(file []byte) string {
|
||||||
client := gosseract.NewClient()
|
resMap := httpclient.GetClient(time.Second*30).Post("https://api.textin.com/ai/service/v2/recognize/multipage", file, "x-ti-app-id", "d367747801bba61cd45026ebee91c784", "x-ti-secret-code", "f79c9c361d7bdb92195bd8c63bedffa0").Map()
|
||||||
defer client.Close()
|
res := struct {
|
||||||
err := client.SetImageFromBytes(image)
|
Result struct {
|
||||||
if err != nil {
|
Pages []struct {
|
||||||
fmt.Println(err)
|
Lines []struct {
|
||||||
log.DefaultLogger.Error("ocr setimg error", "err", err)
|
Text string
|
||||||
|
} `json:"lines"`
|
||||||
|
} `json:"pages"`
|
||||||
|
} `json:"result"`
|
||||||
|
}{}
|
||||||
|
//log.DefaultLogger.Info("Result", "", resMap)
|
||||||
|
//log.DefaultLogger.Error("ocrres err111", "err", errors.New(u.BRed(resMap["message"])), "rescode", reflect.TypeOf(resMap["code"]).String(), "rescod1e", reflect.TypeOf(resMap["code"]).Kind())
|
||||||
|
if u.Int(resMap["code"]) != 200 {
|
||||||
|
log.DefaultLogger.Error("ocrres err", "err", errors.New(u.BRed(resMap["message"])), "rescode", resMap["code"])
|
||||||
|
fmt.Println(u.BRed(resMap["message"]))
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
fmt.Println(u.Red("111"))
|
str := ""
|
||||||
text, err := client.Text()
|
u.Convert(resMap, &res)
|
||||||
fmt.Println(text)
|
if len(res.Result.Pages) < 1 {
|
||||||
if err != nil {
|
log.DefaultLogger.Error("no characters recognized")
|
||||||
fmt.Println(err)
|
|
||||||
log.DefaultLogger.Error("ocr error", "err", err)
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return text
|
for _, k := range res.Result.Pages[len(res.Result.Pages)-1].Lines {
|
||||||
|
str += "" + k.Text
|
||||||
|
}
|
||||||
|
//log.DefaultLogger.Info("OCRResult", "Map", resMap, "Text", str)
|
||||||
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildImgDetectionPrompt(content string) string {
|
func buildImgDetectionPrompt(content string) string {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// 初始化 WebSocket 连接
|
// 初始化 WebSocket 连接
|
||||||
const socket = new WebSocket('ws://your-websocket-server-url'); // 替换为实际的 WebSocket URL
|
const socket = new WebSocket('ws://localhost:9000/socket'); // 替换为实际的 WebSocket URL
|
||||||
|
|
||||||
// 监听 WebSocket 打开事件
|
// 监听 WebSocket 打开事件
|
||||||
socket.addEventListener('open', () => {
|
socket.addEventListener('open', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user