TLeonidas's picture
Update app.py
d7528b5 verified
raw history blame
No virus
1.31 kB
import gradio as gr
import joblib
# Load your serialized objects
model = joblib.load('random_forest_model_3labels2.joblib')
encoder = joblib.load('label_encoder2.joblib')
vectorizer = joblib.load('count_vectorizer2.joblib')
def predict(input_text):
# Preprocess the input with your vectorizer and encoder as needed
# For example, if your model expects vectorized input:
vectorized_text = vectorizer.transform([input_text])
# Make a prediction
prediction = model.predict(vectorized_text)
# If your model's output needs to be decoded (optional)
decoded_prediction = encoder.inverse_transform(prediction)
# Return the prediction (you might want to convert it into a more readable form)
return prediction[0] # Modify this according to your needs
# Setup the Gradio interface
iface = gr.Interface(fn=predict,
inputs=gr.Textbox(lines=2, placeholder="Enter Text Here..."),
outputs="text",
description="Detects hate speech in text. Outputs 'Neutral or Ambiguous', 'Not Hate', or 'Offensive or Hate Speech'.")
# Launch the app
iface.launch()
"""
import gradio as gr
def greet(name):
return "Hello " + name + "!!"
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()
"""