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(
"""
Amharic Hate Speech Detector đľď¸ââď¸
Type an Amharic sentence and let our model analyze it!
""",
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"""
""",
unsafe_allow_html=True
)
# Display the result with styled message
st.markdown(f"{prediction}
", unsafe_allow_html=True)
else:
st.warning("Please enter some text to analyze.")