naftalindeapo commited on
Commit
1f16daf
1 Parent(s): 740c1eb

Upload 3 files

Browse files
Abuse_HateSpe_Profanity_Detector_BERT.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import torch
3
+ import gradio as gr
4
+ from transformers import pipeline
5
+
6
+ # Load the models
7
+ Abuse_detector = pipeline("text-classification", model="Hate-speech-CNERG/english-abusive-MuRIL")
8
+ Hate_Speech_detector = pipeline("text-classification", model="cardiffnlp/twitter-roberta-base-hate-latest")
9
+ Profanity_detector = pipeline("text-classification", model="tarekziade/pardonmyai")
10
+
11
+ # Function to classify based on the user's choice
12
+ def classify_text(text, detection_type):
13
+ if detection_type == "Abuse":
14
+ result = Abuse_detector(text)
15
+ if result[0]['label'] == 'LABEL_0':
16
+ result[0]['label'] = "Not-abusive"
17
+ elif result[0]['label'] == 'LABEL_1':
18
+ result[0]['label'] = "Abusive"
19
+ elif detection_type == "Hate Speech":
20
+ result = Hate_Speech_detector(text)
21
+
22
+ elif detection_type == "Profanity":
23
+ result = Profanity_detector(text)
24
+
25
+ return result[0]
26
+
27
+ # Gradio interface
28
+ interface = gr.Interface(
29
+ fn=classify_text,
30
+ inputs=[gr.Textbox(label="Enter text"), gr.Radio(["Abuse", "Hate Speech", "Profanity"], label="Detection Type")],
31
+ outputs="json",
32
+ title="Abuse, Hate Speech, and Profanity Detection",
33
+ description="Enter text and select the type of detection you want."
34
+ )
35
+
36
+ # Launch the Gradio app
37
+ if __name__ == "__main__":
38
+ interface.launch(share=True)
recquirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio