forked from olivia-ai/olivia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (54 loc) · 1.58 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/olivia-ai/olivia/locales"
"github.com/olivia-ai/olivia/training"
"github.com/olivia-ai/olivia/dashboard"
"github.com/olivia-ai/olivia/util"
"github.com/gookit/color"
"github.com/olivia-ai/olivia/network"
"github.com/olivia-ai/olivia/server"
)
var neuralNetworks = map[string]network.Network{}
func main() {
port := flag.String("port", "8080", "The port for the API and WebSocket.")
localesFlag := flag.String("re-train", "", "The locale(s) to re-train.")
flag.Parse()
// If the locales flag isn't empty then retrain the given models
if *localesFlag != "" {
reTrainModels(*localesFlag)
}
// Print the Olivia ascii text
oliviaASCII := string(util.ReadFile("res/olivia-ascii.txt"))
fmt.Println(color.FgLightGreen.Render(oliviaASCII))
// Create the authentication token
dashboard.Authenticate()
for _, locale := range locales.Locales {
util.SerializeMessages(locale.Tag)
neuralNetworks[locale.Tag] = training.CreateNeuralNetwork(
locale.Tag,
false,
)
}
// Get port from environment variables if there is
if os.Getenv("PORT") != "" {
*port = os.Getenv("PORT")
}
// Serves the server
server.Serve(neuralNetworks, *port)
}
// reTrainModels retrain the given locales
func reTrainModels(localesFlag string) {
// Iterate locales by separating them by comma
for _, localeFlag := range strings.Split(localesFlag, ",") {
path := fmt.Sprintf("res/locales/%s/training.json", localeFlag)
err := os.Remove(path)
if err != nil {
fmt.Printf("Cannot re-train %s model.", localeFlag)
return
}
}
}