CoolFace
Apppublic

pelinbalci/LanguageDetection

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
model.py40 linesDownload Raw Back to root
1import pickle2import re3from pathlib import Path4 5__version__ = "0.1.0"6 7BASE_DIR = Path(__file__).resolve(strict=True).parent8 9 10with open(f"{BASE_DIR}/trained_pipeline-{__version__}.pkl", "rb") as f:11    model = pickle.load(f)12 13 14classes = [15    "Arabic",16    "Danish",17    "Dutch",18    "English",19    "French",20    "German",21    "Greek",22    "Hindi",23    "Italian",24    "Kannada",25    "Malayalam",26    "Portugeese",27    "Russian",28    "Spanish",29    "Sweedish",30    "Tamil",31    "Turkish",32]33 34 35def predict_pipeline(text):36    text = re.sub(r'[!@#$(),\n"%^*?\:;~`0-9]', " ", text)37    text = re.sub(r"[[]]", " ", text)38    text = text.lower()39    pred = model.predict([text])40    return classes[pred[0]]