sandbox338 commited on
Commit
3cc2689
·
verified ·
1 Parent(s): faf58d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -17
app.py CHANGED
@@ -1,32 +1,22 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load the model from Hugging Face Hub
5
  classifier = pipeline("text-classification", model="sandbox338/hatespeech")
6
 
7
- # Define the label-to-number mapping
8
- label_to_number = {
9
- "Non-hate speech": 0,
10
- "Political hate speech": 1,
11
- "Offensive language": 2
12
- }
13
-
14
- # Define the function for the interface
15
  def classify_text(text):
16
- results = classifier(text)
17
- # Get the label and map it to the corresponding number
18
- label = results[0]['label']
19
- return label_to_number[label]
20
 
21
- # Create the interface
22
  interface = gr.Interface(
23
  fn=classify_text,
24
  inputs=gr.Textbox(lines=4, placeholder="Enter Swahili text here..."),
25
  outputs="text",
26
  title="Swahili Hate Speech Classifier",
27
- description="Classifies text as Non-hate speech, Political hate speech, or Offensive language."
28
  )
29
 
30
- # Launch the interface (only used if running locally)
31
  if __name__ == "__main__":
32
- interface.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load the model
5
  classifier = pipeline("text-classification", model="sandbox338/hatespeech")
6
 
7
+ # Define function to return only the label
 
 
 
 
 
 
 
8
  def classify_text(text):
9
+ result = classifier(text)[0]
10
+ return result['label']
 
 
11
 
12
+ # Gradio interface
13
  interface = gr.Interface(
14
  fn=classify_text,
15
  inputs=gr.Textbox(lines=4, placeholder="Enter Swahili text here..."),
16
  outputs="text",
17
  title="Swahili Hate Speech Classifier",
18
+ description="Classifies text as one of: Non-hate speech, Political hate speech, or Offensive language."
19
  )
20
 
 
21
  if __name__ == "__main__":
22
+ interface.launch()