slyskawa's picture
Update app.py
6ae6997 verified
import gradio as gr
import joblib
logistic_pipeline = joblib.load('logistic_pipeline.pkl')
knn_pipeline = joblib.load('knn_pipeline.pkl')
def predict_class_probabilities(text, model_choice):
if model_choice == "Logistic Regression":
probabilities = logistic_pipeline.predict_proba([text])[0]
else:
probabilities = knn_pipeline.predict_proba([text])[0]
return {'Positive': probabilities[1], 'Negative': probabilities[0]}
#Gradio interface
input_text = gr.Textbox(lines=5, label="Enter your review comment")
model_choice = gr.Dropdown(choices=["Logistic Regression", "KNN"], label="Choose a model")
output_probs = gr.Label()
iface = gr.Interface(fn=predict_class_probabilities,
inputs=[input_text, model_choice],
outputs=output_probs,
title="Sentiment Emotion Predictor",
description="Predict sentiment of review (positive or negative).")
iface.launch()