File size: 1,321 Bytes
a90d470
3a7236e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a90d470
 
 
 
 
 
3a7236e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import gradio as gr
import joblib

# Function to load your model (adjust the path and method if needed)
def load_model():
    # This path is relative to the root of your Hugging Face Space
    model_path = "./en-hate-speech-detection-3label"
    model = joblib.load(model_path)
    return model

# Function to predict hate speech from text input
def predict_hate_speech(text):
    model = load_model()  # Load your model
    prediction = model.predict([text])
    # Assuming your model outputs integers representing classes, you might want to convert
    # these to more readable labels. Adjust these labels according to your model's output.
    labels = {0: 'Neutral or Ambiguous', 1: 'Not Hate', 2: 'Offensive or Hate Speech'}
    return labels[prediction[0]]

# Adjusted Gradio interface to take text input and output model predictions
iface = gr.Interface(fn=predict_hate_speech, 
                     inputs=gr.inputs.Textbox(lines=2, placeholder="Enter Text Here..."), 
                     outputs="text", 
                     description="Detects hate speech in text. Outputs 'No Hate Speech', 'Offensive Language', or 'Hate Speech'.")
iface.launch()



"""
import gradio as gr

def greet(name):
    return "Hello " + name + "!!"

iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()
"""