TLeonidas commited on
Commit
3a7236e
1 Parent(s): 1ce6054

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py CHANGED
@@ -1,7 +1,37 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def greet(name):
4
  return "Hello " + name + "!!"
5
 
6
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
  iface.launch()
 
 
1
  import gradio as gr
2
+ import joblib
3
+
4
+ # Function to load your model (adjust the path and method if needed)
5
+ def load_model():
6
+ # This path is relative to the root of your Hugging Face Space
7
+ model_path = "./en-hate-speech-detection-3label"
8
+ model = joblib.load(model_path)
9
+ return model
10
+
11
+ # Function to predict hate speech from text input
12
+ def predict_hate_speech(text):
13
+ model = load_model() # Load your model
14
+ prediction = model.predict([text])
15
+ # Assuming your model outputs integers representing classes, you might want to convert
16
+ # these to more readable labels. Adjust these labels according to your model's output.
17
+ labels = {0: 'Neutral or Ambiguous', 1: 'Not Hate', 2: 'Offensive or Hate Speech'}
18
+ return labels[prediction[0]]
19
+
20
+ # Adjusted Gradio interface to take text input and output model predictions
21
+ iface = gr.Interface(fn=predict_hate_speech,
22
+ inputs=gr.inputs.Textbox(lines=2, placeholder="Enter Text Here..."),
23
+ outputs="text",
24
+ description="Detects hate speech in text. Outputs 'No Hate Speech', 'Offensive Language', or 'Hate Speech'.")
25
+ iface.launch()
26
+
27
+
28
+
29
+ """
30
+ import gradio as gr
31
 
32
  def greet(name):
33
  return "Hello " + name + "!!"
34
 
35
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
36
  iface.launch()
37
+ """