do not use language detector model on dev mode.

because it's slow.
This commit is contained in:
fiatjaf
2023-12-31 17:50:01 -03:00
parent d1d172b96c
commit 91a0ea768b
3 changed files with 28 additions and 21 deletions

View File

@@ -115,17 +115,19 @@ type ScriptRange struct {
func initializeImageDrawingStuff() error { func initializeImageDrawingStuff() error {
// language detector // language detector
detector = lingua.NewLanguageDetectorBuilder().FromLanguages( if !s.SkipLanguageModel {
lingua.Japanese, detector = lingua.NewLanguageDetectorBuilder().FromLanguages(
lingua.Persian, lingua.Japanese,
lingua.Chinese, lingua.Persian,
lingua.Thai, lingua.Chinese,
lingua.Hebrew, lingua.Thai,
lingua.Arabic, lingua.Hebrew,
lingua.Bengali, lingua.Arabic,
lingua.Hindi, lingua.Bengali,
lingua.Korean, lingua.Hindi,
).WithLowAccuracyMode().Build() lingua.Korean,
).WithLowAccuracyMode().Build()
}
// script detector material // script detector material
for _, srange := range language.ScriptRanges { for _, srange := range language.ScriptRanges {
@@ -252,11 +254,15 @@ gotScriptIndex:
direction := directionMap[idx] direction := directionMap[idx]
lng := language.Language("en-us") lng := language.Language("en-us")
lang, ok := detector.DetectLanguageOf(string(paragraph)) if detector == nil {
if ok {
lng = language.Language(lang.IsoCode639_1().String())
} else {
lng = defaultLanguageMap[idx] lng = defaultLanguageMap[idx]
} else {
lang, ok := detector.DetectLanguageOf(string(paragraph))
if ok {
lng = language.Language(lang.IsoCode639_1().String())
} else {
lng = defaultLanguageMap[idx]
}
} }
return lng, script, direction, face return lng, script, direction, face

View File

@@ -1,7 +1,7 @@
export PATH := "./node_modules/.bin:" + env_var('PATH') export PATH := "./node_modules/.bin:" + env_var('PATH')
dev: dev:
TAILWIND_DEBUG=true go build -o /tmp/njump && /tmp/njump TAILWIND_DEBUG=true SKIP_LANGUAGE_MODEL=true go build -o /tmp/njump && /tmp/njump
check-samples: check-samples:
#!/usr/bin/env xonsh #!/usr/bin/env xonsh

11
main.go
View File

@@ -19,11 +19,12 @@ import (
) )
type Settings struct { type Settings struct {
Port string `envconfig:"PORT" default:"2999"` Port string `envconfig:"PORT" default:"2999"`
Domain string `envconfig:"DOMAIN" default:"njump.me"` Domain string `envconfig:"DOMAIN" default:"njump.me"`
DiskCachePath string `envconfig:"DISK_CACHE_PATH" default:"/tmp/njump-internal"` DiskCachePath string `envconfig:"DISK_CACHE_PATH" default:"/tmp/njump-internal"`
EventStorePath string `envconfig:"EVENT_STORE_PATH" default:"/tmp/njump-db"` EventStorePath string `envconfig:"EVENT_STORE_PATH" default:"/tmp/njump-db"`
TailwindDebug bool `envconfig:"TAILWIND_DEBUG"` TailwindDebug bool `envconfig:"TAILWIND_DEBUG"`
SkipLanguageModel bool `envconfig:"SKIP_LANGUAGE_MODEL"`
} }
//go:embed static/* //go:embed static/*