SoDehghan commited on
Commit
246976e
·
verified ·
1 Parent(s): c72fd45

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import awesome_streamlit as ast
2
+ import streamlit as st
3
+ import requests
4
+ import time
5
+ from transformers import pipeline
6
+ import os
7
+
8
+
9
+ # Set the page configuration
10
+ st.set_page_config(
11
+ page_title="Hate Speech Detection",
12
+ page_icon="📖", #":bar_chart:"
13
+ layout='centered'
14
+ )
15
+
16
+ #title = r"$\textsf{\small Hate Speech Detection}$"
17
+ #st.title(title)
18
+ #st.write("In this HuggingFace space you will be able to use our Hate Speech Detection model built at [VERİM - Center of Excellence in Data Analytics - Sabanci University](https://github.com/verimsu).")
19
+
20
+
21
+ sentiment_pipeline = pipeline(task = "text-classification", model = "gritli/bert-sentiment-analyses-imdb")
22
+ label_dict = {'LABEL_0': 'Hate', 'LABEL_1': 'Non-hate'}
23
+
24
+
25
+ header_tr = r"$\textsf{\scriptsize HSD in Turkish}$"
26
+
27
+ # Turkish
28
+ st.subheader(header_tr)
29
+ tr_input = st.text_area("Enter your text here:", height=50, key="tr_input") #height=30
30
+ if st.button("Click for predictions!", key="tr_predict"):
31
+ with st.spinner('Generating predictions...'):
32
+ result_tr = sentiment_pipeline(tr_input)
33
+ sentiment_tr = result_tr[0]["label"]
34
+ label_dict = {'LABEL_1': 'Hate ❌', 'LABEL_0': 'Non-hate ✅'} #🚫
35
+ sentiment_tr = label_dict[sentiment_tr]
36
+ st.write(f"Detection: {sentiment_tr}")
37
+
38
+
39
+ header_ar = r"$\textsf{\scriptsize HSD in Arabic}$"
40
+ # Arabic
41
+ st.subheader(header_ar)
42
+ ar_input = st.text_area("Enter your text here:", height=50 , key="ar_input")
43
+ if st.button("Click for predictions!", key="ar_predict"):
44
+ with st.spinner('Generating predictions...'):
45
+ result_ar = sentiment_pipeline(ar_input)
46
+ sentiment_ar = result_ar[0]["label"]
47
+ label_dict = {'LABEL_1': 'Hate ❌', 'LABEL_0': 'Non-hate ✅'}
48
+ sentiment_ar = label_dict[sentiment_ar]
49
+ st.write(f"Detection: {sentiment_ar}")
50
+
51
+
52
+ st.sidebar.title("Hate Speech Detection")
53
+ st.sidebar.write("In this HuggingFace space you can use Hate Speech Detection model built at [VERİM - Center of Excellence in Data Analytics - Sabanci University](https://github.com/verimsu).")