File size: 1,357 Bytes
2400e83
a90d470
3a7236e
 
 
 
 
e326036
3a7236e
 
 
 
 
 
 
 
 
 
 
 
 
 
4a8503c
e326036
4a8503c
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
pip install joblib
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 = "./random_forest_model_3labels2.joblib"
    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.Textbox(lines=2, placeholder="Enter Text Here..."), 
                     outputs=labels[prediction[0]], 
                     description="Detects hate speech in text. Outputs 'Neutral or Ambiguous', 'Not Hate', 'Offensive 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()
"""