Spaces:
Sleeping
Sleeping
Update pages/✨second.py
Browse files- pages/✨second.py +12 -14
pages/✨second.py
CHANGED
@@ -12,37 +12,35 @@ def clean(text):
|
|
12 |
text = re.sub(r'@\w+',' ',text) # удаляем упоминания пользователей
|
13 |
text = re.sub(r'#\w+', ' ', text) # удаляем хэштеги
|
14 |
text = re.sub(r'\d+', ' ', text) # удаляем числа
|
15 |
-
text = text.translate(str.maketrans('', '', string.punctuation))
|
16 |
return text
|
17 |
|
18 |
# Загрузка весов модели
|
19 |
|
20 |
-
model_filename = '
|
21 |
with open(model_filename, 'rb') as file:
|
22 |
model = pickle.load(file)
|
23 |
|
24 |
# Загрузка весов векторизатора
|
25 |
vectorizer = CountVectorizer()
|
26 |
-
vectorizer_filename = '
|
27 |
with open(vectorizer_filename, 'rb') as file:
|
28 |
vectorizer = pickle.load(file)
|
29 |
|
30 |
# Само приложение
|
31 |
|
32 |
-
st.title("
|
33 |
-
st.
|
34 |
-
st.write("
|
35 |
-
st.
|
36 |
-
st.write("Just enter the review, and our app will provide you with instant sentiment analysis.")
|
37 |
-
st.write("Make informed decisions about movies with CritiSense!")
|
38 |
-
user_review = st.text_input("Enter your review:", "")
|
39 |
user_review_clean = clean(user_review)
|
40 |
user_features = vectorizer.transform([user_review_clean])
|
41 |
prediction = model.predict(user_features)
|
42 |
|
43 |
-
st.write("
|
44 |
|
45 |
-
if prediction ==
|
46 |
-
st.markdown("<p style='color: green;'>
|
47 |
else:
|
48 |
-
st.markdown("<p style='color: red;'>
|
|
|
|
|
|
12 |
text = re.sub(r'@\w+',' ',text) # удаляем упоминания пользователей
|
13 |
text = re.sub(r'#\w+', ' ', text) # удаляем хэштеги
|
14 |
text = re.sub(r'\d+', ' ', text) # удаляем числа
|
|
|
15 |
return text
|
16 |
|
17 |
# Загрузка весов модели
|
18 |
|
19 |
+
model_filename = 'model_comments_weights.pkl'
|
20 |
with open(model_filename, 'rb') as file:
|
21 |
model = pickle.load(file)
|
22 |
|
23 |
# Загрузка весов векторизатора
|
24 |
vectorizer = CountVectorizer()
|
25 |
+
vectorizer_filename = 'vectorizer_comments_weights.pkl'
|
26 |
with open(vectorizer_filename, 'rb') as file:
|
27 |
vectorizer = pickle.load(file)
|
28 |
|
29 |
# Само приложение
|
30 |
|
31 |
+
st.title("SafeTalk")
|
32 |
+
st.write("Your Personal Comment Filter is an innovative application that harnesses the power of AI to distinguish toxic comments from the rest.")
|
33 |
+
st.write("Empowering users to navigate online discussions with confidence, SafeTalk ensures a more constructive and respectful online community by identifying and flagging harmful content.")
|
34 |
+
user_review = st.text_input("Enter your comment:", "")
|
|
|
|
|
|
|
35 |
user_review_clean = clean(user_review)
|
36 |
user_features = vectorizer.transform([user_review_clean])
|
37 |
prediction = model.predict(user_features)
|
38 |
|
39 |
+
st.write("Comment:", user_review)
|
40 |
|
41 |
+
if prediction == 0:
|
42 |
+
st.markdown("<p style='color: green;'>Non-toxic comment</p>", unsafe_allow_html=True)
|
43 |
else:
|
44 |
+
st.markdown("<p style='color: red;'>Toxic comment</p>", unsafe_allow_html=True)
|
45 |
+
|
46 |
+
|