|
import streamlit as st |
|
from transformers import pipeline |
|
|
|
|
|
model_name = "devaprobs/hate-speech-detection-using-amharic-language" |
|
classifier = pipeline("text-classification", model=model_name) |
|
|
|
|
|
st.set_page_config(page_title="Amharic Hate Speech Detector", page_icon="๐ต๏ธโโ๏ธ", layout="centered") |
|
|
|
|
|
default_bg_color = "#f0f2f6" |
|
bg_color = default_bg_color |
|
|
|
|
|
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 |
|
) |
|
|
|
|
|
user_input = st.text_area("Enter Amharic text here:", height=150, placeholder="แแณแ: แขแตแฎแตแซ แแแแแ แตแแญ...") |
|
|
|
|
|
if st.button("Analyze Text ๐"): |
|
if user_input: |
|
|
|
result = classifier(user_input) |
|
label = result[0]['label'] |
|
score = result[0]['score'] |
|
|
|
|
|
if label == "LABEL_0": |
|
prediction = "Normal Text ๐ข" |
|
color = "#28a745" |
|
else: |
|
prediction = "Hate Speech Detected ๐ด" |
|
color = "#dc3545" |
|
bg_color = "#FFBABA" |
|
|
|
|
|
st.warning("โ ๏ธ Warning: Hate Speech Detected! โ ๏ธ") |
|
|
|
|
|
st.markdown( |
|
f""" |
|
<style> |
|
body {{ background-color: {bg_color}; }} |
|
.stAlert {{ text-align: center; }} |
|
</style> |
|
""", |
|
unsafe_allow_html=True |
|
) |
|
|
|
|
|
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.") |