File size: 832 Bytes
af6755e |
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 |
import gradio as gr
import joblib
# Load your trained model from the model file
model = joblib.load("model.pkl")
# Define a function to use with the Gradio interface
def predict_sentiment(text):
prediction = model.predict([text])[0]
probabilities = model.predict_proba([text])[0]
return {
"Prediction": prediction,
"Probabilities": dict(zip(model.classes_, probabilities))
}
# Create a Gradio interface
interface = gr.Interface(
fn=predict_sentiment,
inputs=gr.Textbox(lines=2, placeholder="Enter your text here..."),
outputs=gr.JSON(label="Prediction and Probabilities"),
title="Sentiment Analysis App",
description="This app predicts sentiment responses using a trained logistic regression model."
)
# Launch the interface
if __name__ == "__main__":
interface.launch()
|