-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
32 lines (25 loc) · 588 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main
import (
"fmt"
"os"
"github.com/Kardbord/hfapigo/v3"
)
const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
func init() {
key := os.Getenv(HuggingFaceTokenEnv)
if key != "" {
hfapigo.SetAPIKey(key)
}
}
const inputImg = "./test-image.png"
func main() {
fmt.Printf("Requesting classification of image: %s\n", inputImg)
resps, err := hfapigo.SendImageClassificationRequest(hfapigo.RecommendedImageClassificationModel, inputImg)
if err != nil {
fmt.Printf("Error: %s\n", err)
return
}
for _, r := range resps {
fmt.Printf("%s: %f\n", r.Label, r.Score)
}
}