File size: 2,216 Bytes
2558d2c
 
 
 
e25301c
62c8d76
2558d2c
 
 
3f6713e
 
 
843eeea
2558d2c
 
 
 
 
 
 
 
 
 
 
 
 
f64ba61
2558d2c
 
 
 
 
 
 
 
 
3f6713e
2558d2c
 
 
 
3f6713e
2558d2c
843eeea
3f6713e
843eeea
3f6713e
843eeea
 
 
 
 
 
 
 
 
 
 
3f6713e
2558d2c
 
 
843eeea
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
import streamlit as st
from transformers import pipeline

# Load the pre-trained model for inference
model_name = "devaprobs/hate-speech-detection-using-amharic-language"
classifier = pipeline("text-classification", model=model_name)

# Configure the Streamlit page
st.set_page_config(page_title="Amharic Hate Speech Detector", page_icon="๐Ÿ•ต๏ธโ€โ™‚๏ธ", layout="centered")

# Set default background color
default_bg_color = "#f0f2f6"
bg_color = default_bg_color

# Add a stylish header with a logo
st.markdown(
    """
    <div style="text-align:center">
        <h1 style="color:#1F618D;">Amharic Hate Speech Detector ๐Ÿ•ต๏ธโ€โ™‚๏ธ</h1>
        <p style="font-size:20px; color:#555;">Type an Amharic sentence and let our model analyze it!</p>
    </div>
    """,
    unsafe_allow_html=True
)

# Input text box for user to enter Amharic text
user_input = st.text_area("Enter Amharic text here:", height=150, placeholder="แˆแˆณแˆŒ: แŠขแ‰ตแ‹ฎแŒตแ‹ซ แˆˆแ‹˜แˆ‹แˆˆแˆ แ‰ตแŠ‘แˆญ...")

# Submit button for classification
if st.button("Analyze Text ๐Ÿš€"):
    if user_input:
        # Get the classification result
        result = classifier(user_input)
        label = result[0]['label']
        score = result[0]['score']

        # Determine if text is hate speech and update color/background
        if label == "LABEL_0":
            prediction = "Normal Text ๐ŸŸข"
            color = "#28a745"
        else:
            prediction = "Hate Speech Detected ๐Ÿ”ด"
            color = "#dc3545"
            bg_color = "#FFBABA"  # Update background to a red color for hate speech

            # Display warning
            st.warning("โš ๏ธ Warning: Hate Speech Detected! โš ๏ธ")

        # Apply the background color dynamically
        st.markdown(
            f"""
            <style>
                body {{ background-color: {bg_color}; }}
                .stAlert {{ text-align: center; }}
            </style>
            """,
            unsafe_allow_html=True
        )

        # Display the result with styled message
        st.markdown(f"<h2 style='text-align: center; color: {color};'>{prediction}</h2>", unsafe_allow_html=True)
    else:
        st.warning("Please enter some text to analyze.")