File size: 4,503 Bytes
f6d3540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3c2395
 
 
 
 
 
 
 
 
 
f6d3540
 
 
 
 
 
 
 
 
 
f5565b2
f6d3540
 
 
 
 
 
 
d3c2395
 
 
f6d3540
 
 
 
 
 
 
 
 
 
 
 
 
d3c2395
f6d3540
 
 
 
 
 
 
 
 
4367cf8
f6d3540
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import streamlit as st
from transformers import pipeline

# Load the HuggingFace pipeline with a binary classification model
# Use a pipeline as a high-level helper
models = {
    "fBert Convabuse": "alexabrahall/fbert_convabuse_ss",
    "fBert HTDM": "alexabrahall/fbert_htdm_ss",
    "hateBert Convabuse": "alexabrahall/hatebert_convabuse_ss",
    "hateBert HTDM": "alexabrahall/hatebert_htdm_ss",
    "berTweet Convabuse": "alexabrahall/bertweet_convabuse_ss",
    "berTweet HTDM": "alexabrahall/bertweet_htdm_ss",
    "roberta Convabuse": "alexabrahall/roberta_convabuse_ss",
    "roberta HTDM": "alexabrahall/roberta_htdm_ss",
    
}

model_descriptions = {
    "fBert Convabuse": "This is the model fBert, trained on the conversational abuse public dataset. It is a binary classification model that predicts whether a given text is abusive or not. The model is based on the fBert architecture and was trained using the Sentence Transformers library.",
    "fBert HTDM": "This is the model fBert, trained on the hate speech public dataset. It is a binary classification model that predicts whether a given text is hate speech or not. The model is based on the fBert architecture and was trained using the Sentence Transformers library.",
    "hateBert Convabuse": "This is the model hateBert, trained on the conversational abuse public dataset. It is a binary classification model that predicts whether a given text is abusive or not. The model is based on the hateBert architecture and was trained using the Sentence Transformers library.",
    "hateBert HTDM": "This is the model hateBert, trained on the hate speech public dataset. It is a binary classification model that predicts whether a given text is hate speech or not. The model is based on the hateBert architecture and was trained using the Sentence Transformers library.",
    "berTweet Convabuse": "This is the model berTweet, trained on the conversational abuse public dataset. It is a binary classification model that predicts whether a given text is abusive or not. The model is based on the berTweet architecture and was trained using the Sentence Transformers library.",
    "berTweet HTDM": "This is the model berTweet, trained on the hate speech public dataset. It is a binary classification model that predicts whether a given text is hate speech or not. The model is based on the berTweet architecture and was trained using the Sentence Transformers library.",
    "roberta Convabuse": "This is the model roberta, trained on the conversational abuse public dataset. It is a binary classification model that predicts whether a given text is abusive or not. The model is based on the roberta architecture and was trained using the Sentence Transformers library.",
    "roberta HTDM": "This is the model roberta, trained on the hate speech public dataset. It is a binary classification model that predicts whether a given text is hate speech or not. The model is based on the roberta architecture and was trained using the Sentence Transformers library.",
}


def classify_text(text, model):
    classifier = pipeline("text-classification", model=model)
    # Use the model to predict the class of the input text
    results = classifier(text)
    return results

# Streamlit app layout
st.title("Homotransphobia Detection App")
st.markdown("[By Alex Abrahall](https://huggingface.co/alexabrahall)", unsafe_allow_html=True)
st.write("Enter the text you want to classify:")

# Input box for user text
user_input = st.text_input("")


selected_model = st.selectbox("Select Model", options=list(models.keys()))
selected_model_description = model_descriptions[selected_model]
st.write("Model Description:")
st.write(selected_model_description)

label_map ={
    "LABEL_0": "Not Homotransphobic",
    "LABEL_1": "Homotransphobic"

}


# Button to classify text
if st.button('Classify'):
    prediction_raw_text = st.empty()
    prediction_text = st.empty()
    
    
    loading_text = st.text("Predicting... (if the model has not been used before, this may take a while)")
    # Classify the text
    prediction = classify_text(user_input, models[selected_model])

    loading_text.empty()
    
    # Display the result
    prediction_raw_text.write("Prediction:")
    print(prediction)
    prediction_text.markdown(f"The text is <span style='color: {'red' if prediction[0]['label'] == 'LABEL_1' else 'green'}'>{label_map[prediction[0]['label']]}</span> with a confidence of {prediction[0]['score']*100}%", unsafe_allow_html=True)