mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-12-23 07:36:38 +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
|
||||
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]
|
||||
|
|
Loading…
Reference in a new issue