Gurucharan11204's picture
Add Gradio app and model files
af6755e
raw
history blame contribute delete
832 Bytes
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()