File size: 1,634 Bytes
571af81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0695e07
571af81
 
0695e07
 
 
 
 
 
 
571af81
 
c755336
571af81
 
 
 
 
 
 
 
 
 
 
fa988c2
571af81
 
 
fa988c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import streamlit as st 
from transformers import pipeline
import pandas as pd

# options to choose 2 models 
option = st.selectbox(
    'Choose your model',
    ("cardiffnlp/twitter-roberta-base-sentiment-latest", "yiyanghkust/finbert-tone"))

# class for toxicity
labels = ["toxic", "severe_toxic", "obscene", "threat", "insult", "identity_hate"] 

# text area to get the input text from the user 
text = st.text_area("enter text")

# col1: for showing tweet
# col2: for showing toxicity class
# col3: for showing the probability
col1, col2, col3 = st.columns(3)

# display the prediction if and only if text is entered and model is chose
if text and option:


    dd = {
        "labels": labels,
        "values": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]
    }
    
    #shows which model was used
    st.write(f"Analyzed with {option} model")
    
    #tokenizer = AutoTokenizer.from_pretrained(option)
    #prediction = model[option].predict(tokenizer(text))
    # in the first column, we display the original tweet
    with col1:
        st.header("Original Tweet")
        st.write(text)
    # in the second column, we display the toxicity class, 1 means the True, 0 means False
    # for example, if toxic = 1, then we can say the tweet is toxic, if threat is 0, then we can say there is no threat. 
    # if the value given by the prediction is above threshold, we put 1, 0 otherwise. 
    with col2:
        st.header("Toxicity class")
        st.write(dd)
    # in the third and last collumn, we display the probability of each category, sorted in descending order
    with col3:
        st.header("Probability")
        st.write(dd)