devaprobs's picture
create app.py
2558d2c verified
raw
history blame
1.74 kB
import streamlit as st
from transformers import pipeline
# Load the pre-trained model for inference
model_name = "devaprobs/amharic-hate-speech-detection"
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")
st.markdown("<style> body { background-color: #f0f2f6; } </style>", unsafe_allow_html=True)
# 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']
# Map label to understandable output
if label == "LABEL_0":
prediction = "Normal Text 🟒"
color = "#28a745"
else:
prediction = "Hate Speech πŸ”΄"
color = "#dc3545"
# Display the result with styled message
st.markdown(f"<h2 style='text-align: center; color: {color};'>{prediction}</h2>", unsafe_allow_html=True)
st.write(f"Confidence: {score * 100:.2f}%")
else:
st.warning("Please enter some text to analyze.")