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,6 +115,7 @@ type ScriptRange struct {
func initializeImageDrawingStuff() error { func initializeImageDrawingStuff() error {
// language detector // language detector
if !s.SkipLanguageModel {
detector = lingua.NewLanguageDetectorBuilder().FromLanguages( detector = lingua.NewLanguageDetectorBuilder().FromLanguages(
lingua.Japanese, lingua.Japanese,
lingua.Persian, lingua.Persian,
@@ -126,6 +127,7 @@ func initializeImageDrawingStuff() error {
lingua.Hindi, lingua.Hindi,
lingua.Korean, lingua.Korean,
).WithLowAccuracyMode().Build() ).WithLowAccuracyMode().Build()
}
// script detector material // script detector material
for _, srange := range language.ScriptRanges { for _, srange := range language.ScriptRanges {
@@ -252,12 +254,16 @@ gotScriptIndex:
direction := directionMap[idx] direction := directionMap[idx]
lng := language.Language("en-us") lng := language.Language("en-us")
if detector == nil {
lng = defaultLanguageMap[idx]
} else {
lang, ok := detector.DetectLanguageOf(string(paragraph)) lang, ok := detector.DetectLanguageOf(string(paragraph))
if ok { if ok {
lng = language.Language(lang.IsoCode639_1().String()) lng = language.Language(lang.IsoCode639_1().String())
} else { } else {
lng = defaultLanguageMap[idx] 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

View File

@@ -24,6 +24,7 @@ type Settings struct {
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/*