mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2025-04-22 14:59:17 +00:00
Fix div by zero error
This commit is contained in:
parent
8ba054c786
commit
9184c382db
1 changed files with 1 additions and 1 deletions
|
@ -72,7 +72,7 @@ def detect_languages(text):
|
||||||
|
|
||||||
# sort the candidates descending based on the detected confidence
|
# sort the candidates descending based on the detected confidence
|
||||||
candidates.sort(
|
candidates.sort(
|
||||||
key=lambda l: (l.confidence * l.text_length) / text_length_total, reverse=True
|
key=lambda l: 0 if text_length_total == 0 else (l.confidence * l.text_length) / text_length_total, reverse=True
|
||||||
)
|
)
|
||||||
|
|
||||||
return [{"confidence": l.confidence, "language": l.code} for l in candidates]
|
return [{"confidence": l.confidence, "language": l.code} for l in candidates]
|
||||||
|
|
Loading…
Add table
Reference in a new issue