From 4ea9708d0f902158f35845bc45a70d7743093a59 Mon Sep 17 00:00:00 2001 From: Scott Hale Date: Thu, 3 Oct 2024 14:17:03 +0100 Subject: [PATCH] Different way to replace new lines (#459) Co-authored-by: computermacgyver --- app/main/lib/langid.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/main/lib/langid.py b/app/main/lib/langid.py index b125f042..dcb7dc8c 100644 --- a/app/main/lib/langid.py +++ b/app/main/lib/langid.py @@ -1,7 +1,6 @@ # 3rd party langid providers from flask import current_app as app import json -import re from google.cloud import translate_v2 as translate # import requests # Used for MicrosoftLangidProvider @@ -88,7 +87,7 @@ class FastTextLangidProvider: fasttext_model = fasttext.load_model("extra/fasttext_language_id/lid.176.ftz") @staticmethod def langid(text): - prediction = list(FastTextLangidProvider.fasttext_model.predict(re.sub("[\n\r]"," ",text,re.MULTILINE))) + prediction = list(FastTextLangidProvider.fasttext_model.predict(text.replace("\n"," "))) # prediction is a list of tuples, e.g., [('__label__en',), array([0.22517213])] language = prediction[0][0].split("__")[-1]