SoDehghan commited on
Commit
71a4d6b
β€’
1 Parent(s): 6275755

Update models/hsd_tr.py

Browse files
Files changed (1) hide show
  1. models/hsd_tr.py +15 -16
models/hsd_tr.py CHANGED
@@ -5,22 +5,21 @@ import time
5
  from transformers import pipeline
6
  import os
7
 
8
- sentiment_pipeline = pipeline(task = "text-classification", model = "gritli/bert-sentiment-analyses-imdb")
9
- label_dict = {'LABEL_0': 'Hate', 'LABEL_1': 'Non-hate'}
 
 
10
 
 
 
 
 
 
 
 
 
11
 
12
- #st.title("Hate Speech Detection in Turkish with HuggingFace Spaces")
13
- #st.write("Enter a Turkish sentence here:")
14
- #user_input = st.text_input(" ")
15
-
16
- user_input = st.text_input("Enter your text here:",)
17
 
18
- #if user_input:
19
- if st.button("Click for predictions!"):
20
- with st.spinner('Generating predictions...'):
21
- result = sentiment_pipeline(user_input)
22
- sentiment = result[0]["label"]
23
- label_dict = {'LABEL_0': 'Hate', 'LABEL_1': 'Non-hate'}
24
- sentiment = label_dict[sentiment]
25
- #st.write(f"Detection: {sentiment}")
26
- #st.success(sentiment)
 
5
  from transformers import pipeline
6
  import os
7
 
8
+ # Turkish
9
+ sentiment_pipeline_tr = pipeline(task = "text-classification", model = "SoDehghan/BERTurk-hate-speech") # "gritli/bert-sentiment-analyses-imdb"
10
+ header_tr = r"$\textsf{\scriptsize HSD in Turkish}$"
11
+ st.subheader(header_tr)
12
 
13
+ tr_input = st.text_area("Enter your text here:", height=50, key="tr_input") #height=30
14
+ if st.button("Click for predictions!", key="tr_predict"):
15
+ st.write(" ")
16
+ with st.spinner('Generating predictions...'):
17
+ result_tr = sentiment_pipeline_tr(tr_input)
18
+ sentiment_tr = result_tr[0]["label"]
19
+ label_dict = {'LABEL_1': 'Hate ❌ ', 'LABEL_0': 'Non-hate βœ… '} #🚫
20
+ sentiment_tr = label_dict[sentiment_tr]
21
 
22
+ strength_tr = " "
23
+ st.write(f"Detection: {sentiment_tr}, Strength: {strength_tr}")
24
+
 
 
25