Spaces:
Sleeping
Sleeping
toxicity
Browse files- pages/toxic.py +22 -0
pages/toxic.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
|
4 |
+
API_URL = "https://api-inference.huggingface.co/models/cointegrated/rubert-tiny-toxicity"
|
5 |
+
headers = {"Authorization": f"Bearer {'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'}"}
|
6 |
+
|
7 |
+
def query(payload):
|
8 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
9 |
+
return response.json()
|
10 |
+
text = st.text_input("Введите комментарий")
|
11 |
+
if text:
|
12 |
+
output = query(text)[0][0].get('label')
|
13 |
+
if output == 'dangerous':
|
14 |
+
st.markdown('<p style="color:red;">ОПАСНЫЙ КОММЕНТАРИЙ</p>', unsafe_allow_html=True)
|
15 |
+
elif output == 'non-toxic':
|
16 |
+
st.markdown('<p style="color:white;">Нормальный комментарий</p>', unsafe_allow_html=True)
|
17 |
+
elif output == 'insult':
|
18 |
+
st.markdown('<p style="color:green;">Оскорбительный комментарий</p>', unsafe_allow_html=True)
|
19 |
+
elif output == 'threat':
|
20 |
+
st.markdown('<p style="color:red;">Угрожающий комментарий</p>', unsafe_allow_html=True)
|
21 |
+
elif output == 'obscenity':
|
22 |
+
st.markdown('<p style="color:pink;">ууу, непристойности</p>', unsafe_allow_html=True)
|