devaprobs commited on
Commit
3f6713e
·
verified ·
1 Parent(s): 48db9a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -4
app.py CHANGED
@@ -7,7 +7,10 @@ classifier = pipeline("text-classification", model=model_name)
7
 
8
  # Configure the Streamlit page
9
  st.set_page_config(page_title="Amharic Hate Speech Detector", page_icon="🕵️‍♂️", layout="centered")
10
- st.markdown("<style> body { background-color: #f0f2f6; } </style>", unsafe_allow_html=True)
 
 
 
11
 
12
  # Add a stylish header with a logo
13
  st.markdown(
@@ -31,16 +34,39 @@ if st.button("Analyze Text 🚀"):
31
  label = result[0]['label']
32
  score = result[0]['score']
33
 
34
- # Map label to understandable output
35
  if label == "LABEL_0":
36
  prediction = "Normal Text 🟢"
37
  color = "#28a745"
38
  else:
39
- prediction = "Hate Speech 🔴"
40
  color = "#dc3545"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  # Display the result with styled message
43
  st.markdown(f"<h2 style='text-align: center; color: {color};'>{prediction}</h2>", unsafe_allow_html=True)
44
- #st.write(f"Confidence: {score * 100:.2f}%")
45
  else:
46
  st.warning("Please enter some text to analyze.")
 
7
 
8
  # Configure the Streamlit page
9
  st.set_page_config(page_title="Amharic Hate Speech Detector", page_icon="🕵️‍♂️", layout="centered")
10
+
11
+ # Set default background color
12
+ default_bg_color = "#f0f2f6"
13
+ bg_color = default_bg_color
14
 
15
  # Add a stylish header with a logo
16
  st.markdown(
 
34
  label = result[0]['label']
35
  score = result[0]['score']
36
 
37
+ # Determine if text is hate speech and update color/background
38
  if label == "LABEL_0":
39
  prediction = "Normal Text 🟢"
40
  color = "#28a745"
41
  else:
42
+ prediction = "Hate Speech Detected 🔴"
43
  color = "#dc3545"
44
+ bg_color = "#FFBABA" # Update background to a red color for hate speech
45
+
46
+ # Play alarm sound and display warning
47
+ st.warning("⚠️ Warning: Hate Speech Detected! ⚠️")
48
+ st.markdown(
49
+ """
50
+ <audio autoplay>
51
+ <source src="beep-warning-6387.mp3" type="audio/mp3">
52
+ Your browser does not support the audio element.
53
+ </audio>
54
+ """,
55
+ unsafe_allow_html=True
56
+ )
57
+
58
+ # Apply the background color dynamically
59
+ st.markdown(
60
+ f"""
61
+ <style>
62
+ body {{ background-color: {bg_color}; }}
63
+ .stAlert {{ text-align: center; }}
64
+ </style>
65
+ """,
66
+ unsafe_allow_html=True
67
+ )
68
 
69
  # Display the result with styled message
70
  st.markdown(f"<h2 style='text-align: center; color: {color};'>{prediction}</h2>", unsafe_allow_html=True)
 
71
  else:
72
  st.warning("Please enter some text to analyze.")