import streamlit as st from transformers import pipeline # Turkish #sentiment_pipeline_tr = pipeline(task = "text-classification", model = "SoDehghan/BERTurk-hate-speech-detection") # "gritli/bert-sentiment-analyses-imdb" #sentiment_pipeline_tr_test = pipeline(task = "text-classification", model = "SoDehghan/test") strength_pipeline_tr = pipeline(task = "text-classification", model = "SoDehghan/BERTurk-hate-speech-strength-prediction") def write(): st.markdown( """ # Hate Speech Detection in Turkish """ ) tr_input = st.text_area("Enter your text here:", height=50, key="tr_input") #height=30 if st.button("Model prediction", key="tr_predict"): st.write(" ") with st.spinner('Generating predictions...'): #result_sentiment_tr = sentiment_pipeline_tr(tr_input) #sentiment_tr = result_sentiment_tr[0]["label"] #label_dict_sentiment = {'LABEL_1': 'Detection: Hate ❌', 'LABEL_0': 'Detection: Non-hate ✅'} #sentiment_tr = label_dict_sentiment[sentiment_tr] #result_sentiment_tr_test = sentiment_pipeline_tr_test(tr_input) #sentiment_tr_test = result_sentiment_tr_test[0]["label"] #label_dict_sentiment = {'LABEL_1': 'Detection: Hate ❌', 'LABEL_0': 'Detection: Non-hate ✅'} #sentiment_tr_test = label_dict_sentiment[sentiment_tr_test] result_strength_tr = strength_pipeline_tr(tr_input) strength_tr = result_strength_tr[0]["label"] label_dict_strength = {'LABEL_0': 'Strength: 0 (No-hate)', 'LABEL_1': 'Strength: 1 (Insult)', 'LABEL_2': 'Strength: 2 (Exclusion)', 'LABEL_3': 'Strength: 3 (Wishing harm)', 'LABEL_4': 'Strength: 4 (Threatening harm)'} label_dict_sentiment = {'LABEL_0': 'Detection: No-hate ✅', 'LABEL_1': 'Detection: Hate ❌', 'LABEL_2': 'Detection: Hate ❌', 'LABEL_3': 'Detection: Hate ❌', 'LABEL_4': 'Detection: Hate ❌',} sentiment_tr = label_dict_sentiment[strength_tr] strength_tr = label_dict_strength[strength_tr] st.write(sentiment_tr) st.write(strength_tr) #st.write(sentiment_tr_test) #st.success(sentiment_tr) #st.success(strength_tr)