Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import joblib
|
| 3 |
import numpy as np
|
|
|
|
| 4 |
|
| 5 |
# Load models (change paths to where your .pkl files are stored)
|
| 6 |
logreg_model = joblib.load('best_lr_model.pkl')
|
| 7 |
knn_model = joblib.load('best_knn_model.pkl')
|
| 8 |
-
svc_model = joblib.load('best_svc_model.pkl')
|
| 9 |
rf_model = joblib.load('best_rf_model.pkl')
|
| 10 |
|
| 11 |
# Preprocessing: Load the same vectorizer you used during training
|
| 12 |
-
from sklearn.feature_extraction.text import CountVectorizer
|
| 13 |
vectorizer = joblib.load('vectorizer.pkl')
|
| 14 |
|
| 15 |
# Define the function to predict sentiment
|
|
@@ -17,6 +17,7 @@ def predict_sentiment(review_text, model_name):
|
|
| 17 |
# Preprocess the review text using the same vectorizer used during training
|
| 18 |
transformed_text = vectorizer.transform([review_text]) # Transform the input review text
|
| 19 |
|
|
|
|
| 20 |
if model_name == "Logistic Regression":
|
| 21 |
model = logreg_model
|
| 22 |
elif model_name == "K-Nearest Neighbors":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import joblib
|
| 3 |
import numpy as np
|
| 4 |
+
from sklearn.feature_extraction.text import CountVectorizer
|
| 5 |
|
| 6 |
# Load models (change paths to where your .pkl files are stored)
|
| 7 |
logreg_model = joblib.load('best_lr_model.pkl')
|
| 8 |
knn_model = joblib.load('best_knn_model.pkl')
|
| 9 |
+
svc_model = joblib.load('best_svc_model.pkl') # Ensure this model has 'probability=True' if needed
|
| 10 |
rf_model = joblib.load('best_rf_model.pkl')
|
| 11 |
|
| 12 |
# Preprocessing: Load the same vectorizer you used during training
|
|
|
|
| 13 |
vectorizer = joblib.load('vectorizer.pkl')
|
| 14 |
|
| 15 |
# Define the function to predict sentiment
|
|
|
|
| 17 |
# Preprocess the review text using the same vectorizer used during training
|
| 18 |
transformed_text = vectorizer.transform([review_text]) # Transform the input review text
|
| 19 |
|
| 20 |
+
# Choose model based on the dropdown selection
|
| 21 |
if model_name == "Logistic Regression":
|
| 22 |
model = logreg_model
|
| 23 |
elif model_name == "K-Nearest Neighbors":
|