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