File size: 967 Bytes
5b3324a
 
 
6ae6997
 
5b3324a
6ae6997
 
 
 
 
 
5b3324a
6ae6997
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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()