TLeonidas's picture
Update app.py
3a7236e verified
raw
history blame
1.32 kB
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()
"""