Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
import joblib
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
model = joblib.load("logistic_pipeline.pkl")
|
7 |
-
else: # KNN
|
8 |
-
model = joblib.load("knn_pipeline.pkl")
|
9 |
-
|
10 |
-
prediction = model.predict([review])[0]
|
11 |
-
probabilities = model.predict_proba([review])[0]
|
12 |
-
proba_positive = probabilities[1]
|
13 |
-
result = f"Sentiment: {'Positive' if prediction else 'Negative'} (Confidence: {proba_positive:.2f} for Positive)"
|
14 |
-
return result
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import joblib
|
3 |
|
4 |
+
logistic_pipeline = joblib.load('logistic_pipeline.pkl')
|
5 |
+
knn_pipeline = joblib.load('knn_pipeline.pkl')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
def predict_class_probabilities(text, model_choice):
|
8 |
+
if model_choice == "Logistic Regression":
|
9 |
+
probabilities = logistic_pipeline.predict_proba([text])[0]
|
10 |
+
else:
|
11 |
+
probabilities = knn_pipeline.predict_proba([text])[0]
|
12 |
+
return {'Positive': probabilities[1], 'Negative': probabilities[0]}
|
13 |
|
14 |
+
#Gradio interface
|
15 |
+
input_text = gr.Textbox(lines=5, label="Enter your review comment")
|
16 |
+
model_choice = gr.Dropdown(choices=["Logistic Regression", "KNN"], label="Choose a model")
|
17 |
+
output_probs = gr.Label()
|
18 |
+
|
19 |
+
iface = gr.Interface(fn=predict_class_probabilities,
|
20 |
+
inputs=[input_text, model_choice],
|
21 |
+
outputs=output_probs,
|
22 |
+
title="Sentiment Emotion Predictor",
|
23 |
+
description="Predict sentiment of review (positive or negative).")
|
24 |
+
iface.launch()
|