|
import gradio as gr |
|
import joblib |
|
|
|
|
|
def load_model(): |
|
|
|
model_path = "./en-hate-speech-detection-3label" |
|
model = joblib.load(model_path) |
|
return model |
|
|
|
|
|
def predict_hate_speech(text): |
|
model = load_model() |
|
prediction = model.predict([text]) |
|
|
|
|
|
labels = {0: 'Neutral or Ambiguous', 1: 'Not Hate', 2: 'Offensive or Hate Speech'} |
|
return labels[prediction[0]] |
|
|
|
|
|
iface = gr.Interface(fn=predict_hate_speech, |
|
inputs=gr.Textbox(lines=2, placeholder="Enter Text Here..."), |
|
outputs="text", |
|
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() |
|
""" |
|
|