1 Star 0 Fork 11

muicx / olivia

forked from Gitee 极速下载 / olivia 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 1.58 KB
一键复制 编辑 原始数据 按行查看 历史
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
}
}
}
Go
1
https://gitee.com/bradhuang/olivia.git
git@gitee.com:bradhuang/olivia.git
bradhuang
olivia
olivia
master

搜索帮助