Update inference.py
Browse files- inference.py +6 -13
inference.py
CHANGED
|
@@ -1,21 +1,14 @@
|
|
| 1 |
-
|
| 2 |
import joblib
|
| 3 |
-
from
|
| 4 |
-
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 5 |
-
from sklearn.linear_model import LogisticRegression
|
| 6 |
-
from typing import List
|
| 7 |
|
| 8 |
# Загрузка модели
|
| 9 |
model_path = "model/language_classifier.joblib"
|
| 10 |
model = joblib.load(model_path)
|
| 11 |
|
| 12 |
# Функция для предсказания
|
| 13 |
-
def predict(texts: List[str]):
|
| 14 |
predictions = model.predict(texts)
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
return
|
| 19 |
-
|
| 20 |
-
def postprocess(prediction):
|
| 21 |
-
return {"label": int(prediction[0])}
|
|
|
|
|
|
|
| 1 |
import joblib
|
| 2 |
+
from typing import List, Dict
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# Загрузка модели
|
| 5 |
model_path = "model/language_classifier.joblib"
|
| 6 |
model = joblib.load(model_path)
|
| 7 |
|
| 8 |
# Функция для предсказания
|
| 9 |
+
def predict(texts: List[str]) -> List[Dict[str, float]]:
|
| 10 |
predictions = model.predict(texts)
|
| 11 |
+
results = []
|
| 12 |
+
for prediction in predictions:
|
| 13 |
+
results.append({"label": str(prediction), "score": 1.0})
|
| 14 |
+
return results
|
|
|
|
|
|
|
|
|