Spaces:
Sleeping
Sleeping
pochti final
Browse files
bot/bot.py
CHANGED
@@ -29,7 +29,7 @@ start_keyboard = ReplyKeyboardMarkup(
|
|
29 |
@lru_cache(maxsize=1)
|
30 |
def load_model():
|
31 |
model = BERTClassifier()
|
32 |
-
weights_path = 'bot/
|
33 |
state_dict = torch.load(weights_path, map_location=device)
|
34 |
model.load_state_dict(state_dict)
|
35 |
model.to(device)
|
|
|
29 |
@lru_cache(maxsize=1)
|
30 |
def load_model():
|
31 |
model = BERTClassifier()
|
32 |
+
weights_path = 'bot/model_weights_new.pth'
|
33 |
state_dict = torch.load(weights_path, map_location=device)
|
34 |
model.load_state_dict(state_dict)
|
35 |
model.to(device)
|
images/toxity_metrics.png
DELETED
Binary file (50.2 kB)
|
|
models/model2/__pycache__/model.cpython-310.pyc
CHANGED
Binary files a/models/model2/__pycache__/model.cpython-310.pyc and b/models/model2/__pycache__/model.cpython-310.pyc differ
|
|
models/model2/__pycache__/preprocess_text.cpython-310.pyc
CHANGED
Binary files a/models/model2/__pycache__/preprocess_text.cpython-310.pyc and b/models/model2/__pycache__/preprocess_text.cpython-310.pyc differ
|
|
models/model2/model_weights.pth
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:0b84f9c8041dd44751288c4777723fb4ff4b3886423f9f6efca37e43c6492429
|
3 |
-
size 47712485
|
|
|
|
|
|
|
|
pages/comments.py
DELETED
@@ -1,70 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import torch
|
3 |
-
import sys
|
4 |
-
from pathlib import Path
|
5 |
-
import requests
|
6 |
-
import time
|
7 |
-
import cv2
|
8 |
-
import numpy as np
|
9 |
-
from transformers import AutoTokenizer
|
10 |
-
|
11 |
-
|
12 |
-
st.write("# Оценка степени токсичности пользовательского сообщения")
|
13 |
-
# st.write("Здесь вы можете загрузить картинку со своего устройства, либо при помощи ссылки")
|
14 |
-
|
15 |
-
# Добавление пути к проекту и моделям
|
16 |
-
project_root = Path(__file__).resolve().parents[1]
|
17 |
-
models_path = project_root / 'models'
|
18 |
-
sys.path.append(str(models_path))
|
19 |
-
from models.model2.preprocess_text import TextPreprocessorBERT
|
20 |
-
from models.model2.model import BERTClassifier
|
21 |
-
|
22 |
-
device = 'cpu'
|
23 |
-
|
24 |
-
# Загрузка модели и словаря
|
25 |
-
@st.cache_resource
|
26 |
-
def load_model():
|
27 |
-
model = BERTClassifier()
|
28 |
-
weights_path = models_path / 'model2' / 'model_weights_new.pth'
|
29 |
-
state_dict = torch.load(weights_path, map_location=device)
|
30 |
-
model.load_state_dict(state_dict)
|
31 |
-
model.to(device)
|
32 |
-
model.eval()
|
33 |
-
return model
|
34 |
-
|
35 |
-
@st.cache_resource
|
36 |
-
def load_tokenizer():
|
37 |
-
return AutoTokenizer.from_pretrained('cointegrated/rubert-tiny-toxicity')
|
38 |
-
|
39 |
-
model = load_model()
|
40 |
-
tokenizer = load_tokenizer()
|
41 |
-
|
42 |
-
input_text = st.text_area('Введите текст сообщения')
|
43 |
-
|
44 |
-
if st.button('Предсказать'):
|
45 |
-
# Применяем предобработку
|
46 |
-
preprocessor = TextPreprocessorBERT()
|
47 |
-
preprocessed_text = preprocessor.transform(input_text)
|
48 |
-
|
49 |
-
# Токенизация
|
50 |
-
tokens = tokenizer.encode_plus(
|
51 |
-
preprocessed_text,
|
52 |
-
add_special_tokens=True,
|
53 |
-
truncation=True,
|
54 |
-
max_length=100,
|
55 |
-
padding='max_length',
|
56 |
-
return_tensors='pt'
|
57 |
-
)
|
58 |
-
|
59 |
-
# Получаем input_ids и attention_mask из токенов
|
60 |
-
input_ids = tokens['input_ids'].to(device)
|
61 |
-
attention_mask = tokens['attention_mask'].to(device)
|
62 |
-
|
63 |
-
# Предсказание
|
64 |
-
with torch.no_grad():
|
65 |
-
output = model(input_ids, attention_mask=attention_mask)
|
66 |
-
|
67 |
-
# Интерпретация результата
|
68 |
-
prediction = torch.sigmoid(output).item()
|
69 |
-
st.write(f'Предсказанный класс токсичности: {prediction:.4f}')
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pages/policlinic.py
DELETED
@@ -1,17 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import joblib
|
3 |
-
import pandas as pd
|
4 |
-
from models.model1.Custom_class import TextPreprocessor
|
5 |
-
|
6 |
-
# Load the trained pipeline
|
7 |
-
pipeline = joblib.load('models/model1/logistic_regression_pipeline.pkl')
|
8 |
-
|
9 |
-
# Streamlit application
|
10 |
-
st.title('Классификация отзывов на русском языке')
|
11 |
-
|
12 |
-
input_text = st.text_area('Введите текст отзыва')
|
13 |
-
|
14 |
-
if st.button('Предсказать'):
|
15 |
-
prediction = pipeline.predict(pd.Series([input_text]))
|
16 |
-
st.write(f'Предсказанный класс с помощью логрег: {prediction[0]}')
|
17 |
-
st.write(f'1 - negative, 0 - positive')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|