Spaces:
Runtime error
Runtime error
Commit
·
70e2bb0
1
Parent(s):
14d1947
Upload 2 files
Browse files- model/model.py +40 -0
- model/trained_pipeline-0.1.0.pkl +3 -0
model/model.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pickle
|
| 2 |
+
import re
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
__version__ = "0.1.0"
|
| 6 |
+
|
| 7 |
+
BASE_DIR = Path(__file__).resolve(strict=True).parent
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
with open(f"{BASE_DIR}/trained_pipeline-{__version__}.pkl", "rb") as f:
|
| 11 |
+
model = pickle.load(f)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
classes = [
|
| 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 |
+
|
| 35 |
+
def 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]]
|
model/trained_pipeline-0.1.0.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ab7135c7421b2636cd9fe030d05b883c5ba19ccd13e57195e755a9e43df2bc53
|
| 3 |
+
size 10251835
|