CoolFace
Apppublic

AIGulfCoast2024/Hate_Speech_Text_Classifier

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py40 linesDownload Raw Back to root
1import gradio as gr2import joblib as joblib3 4# Load your serialized objects5model = joblib.load('random_forest_model_3labels2.joblib')6encoder = joblib.load('label_encoder2.joblib')7vectorizer = joblib.load('count_vectorizer2.joblib')8 9def predict(input_text):10    # Preprocess the input with your vectorizer and encoder as needed11    vectorized_text = vectorizer.transform([input_text])12    13    # Make a prediction14    prediction = model.predict(vectorized_text)15    16    # Decode the prediction into a readable label17    decoded_prediction = encoder.inverse_transform(prediction)18    19    # Return the decoded prediction20    return decoded_prediction[0]  #21 22# Setup the Gradio interface23iface = gr.Interface(fn=predict,24                     inputs=gr.Textbox(lines=2, placeholder="Enter Text Here..."),25                     outputs="text",26                     description="Detects hate speech AGAINST GROUPS. Outputs 'Neutral or Ambiguous', 'Not Hate', or 'Offensive or Hate Speech'.")27 28# Launch the app29iface.launch()30 31 32"""33import gradio as gr34 35def greet(name):36    return "Hello " + name + "!!"37 38iface = gr.Interface(fn=greet, inputs="text", outputs="text")39iface.launch()40"""