Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -72,29 +72,46 @@ user_input = st.text_area('',height=200)
|
|
72 |
|
73 |
model_type = st.radio(
|
74 |
"Выберите модель",
|
75 |
-
("fasttext", "ru-BERT")
|
76 |
)
|
77 |
|
78 |
def highlight_obscene_words(text, model_type):
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
if st.button("Проверить текст"):
|
92 |
if user_input.strip():
|
93 |
st.subheader("Результат:")
|
94 |
result = re.split(r'[.\n!?]+', user_input)
|
95 |
result = [part for part in result if part.strip() != ""]
|
96 |
-
if
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
99 |
else:
|
100 |
st.warning("Пожалуйста, введите текст для проверки")
|
|
|
72 |
|
73 |
model_type = st.radio(
|
74 |
"Выберите модель",
|
75 |
+
("fasttext", "ru-BERT","FRIDA")
|
76 |
)
|
77 |
|
78 |
def highlight_obscene_words(text, model_type):
|
79 |
+
if model_type=="FRIDA":
|
80 |
+
result=model_wrapper(text)
|
81 |
+
for item in result:
|
82 |
+
if item.label=="non-toxic":
|
83 |
+
st.markdown(
|
84 |
+
"<span style='background:#47916B;'>{}:приемлемо</span>".format(text),
|
85 |
+
unsafe_allow_html=True
|
86 |
+
)
|
87 |
+
else:
|
88 |
+
st.markdown(
|
89 |
+
"<span style='background:#ffcccc;'>{}:токсично</span>".format(text),
|
90 |
+
unsafe_allow_html=True
|
91 |
+
)
|
92 |
+
else:
|
93 |
+
label, prob=model_wrapper(text.lower(),model_type)
|
94 |
+
if label=='__label__positive':
|
95 |
+
st.markdown(
|
96 |
+
"<span style='background:#47916B;'>{}:приемлемо</span>".format(text),
|
97 |
+
unsafe_allow_html=True
|
98 |
+
)
|
99 |
+
else:
|
100 |
+
st.markdown(
|
101 |
+
"<span style='background:#ffcccc;'>{}:токсично</span>".format(text),
|
102 |
+
unsafe_allow_html=True
|
103 |
+
)
|
104 |
|
105 |
if st.button("Проверить текст"):
|
106 |
if user_input.strip():
|
107 |
st.subheader("Результат:")
|
108 |
result = re.split(r'[.\n!?]+', user_input)
|
109 |
result = [part for part in result if part.strip() != ""]
|
110 |
+
if model_type=="FRIDA":
|
111 |
+
highlight_obscene_words(text,model_type)
|
112 |
+
else:
|
113 |
+
if result!=[]:
|
114 |
+
for text in result:
|
115 |
+
highlight_obscene_words(text,model_type)
|
116 |
else:
|
117 |
st.warning("Пожалуйста, введите текст для проверки")
|