File size: 1,179 Bytes
4c3876c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)