naufalnashif
commited on
Commit
β’
eaab897
1
Parent(s):
895d96f
Update app.py
Browse files
app.py
CHANGED
@@ -78,6 +78,27 @@ def extract_tfidf_features(texts, tfidf_vectorizer):
|
|
78 |
tfidf_model_path = 'X_tfidf_model.joblib'
|
79 |
tfidf_vectorizer = joblib.load(tfidf_model_path)
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
# Fungsi untuk prediksi sentimen
|
82 |
def predict_sentiment(text, model, tfidf_vectorizer, slang_dict):
|
83 |
# Tahap-1: Membersihkan dan normalisasi teks
|
@@ -96,10 +117,6 @@ def predict_sentiment(text, model, tfidf_vectorizer, slang_dict):
|
|
96 |
|
97 |
return sentiment_label
|
98 |
|
99 |
-
# Memuat model sentimen dengan joblib (pastikan path-nya benar)
|
100 |
-
sentiment_model_path = 'ensemble_clf_soft_smote.joblib'
|
101 |
-
sentiment_model = joblib.load(sentiment_model_path)
|
102 |
-
|
103 |
def get_emoticon(sentiment):
|
104 |
if sentiment == "Positif":
|
105 |
emoticon = "π" # Emotikon untuk sentimen positif
|
@@ -123,6 +140,9 @@ def get_table_download_link(df, download_format):
|
|
123 |
# Judul
|
124 |
st.title("Aplikasi ML Analisis Sentimen based on data Biskita Transpakuan")
|
125 |
|
|
|
|
|
|
|
126 |
# Pilihan input teks manual atau berkas XLSX
|
127 |
input_option = st.radio("Pilih metode input:", ("Teks Manual", "Unggah Berkas XLSX"))
|
128 |
|
|
|
78 |
tfidf_model_path = 'X_tfidf_model.joblib'
|
79 |
tfidf_vectorizer = joblib.load(tfidf_model_path)
|
80 |
|
81 |
+
# Fungsi untuk memilih model berdasarkan pilihan pengguna
|
82 |
+
def select_sentiment_model(selected_model):
|
83 |
+
if selected_model == "Random Forest":
|
84 |
+
model_path = 'best_rf_model_smote.joblib'
|
85 |
+
elif selected_model == "Ensemble":
|
86 |
+
model_path = 'ensemble_clf_soft_smote.joblib'
|
87 |
+
elif selected_model == "Naive Bayes":
|
88 |
+
model_path = 'naive_bayes_model_smote.joblib'
|
89 |
+
elif selected_model == "Logistic Regression":
|
90 |
+
model_path = 'logreg_model_smote.joblib'
|
91 |
+
else:
|
92 |
+
# Fallback ke model default jika pilihan tidak valid
|
93 |
+
model_path = 'ensemble_clf_soft_smote.joblib'
|
94 |
+
|
95 |
+
model = joblib.load(model_path)
|
96 |
+
return model
|
97 |
+
|
98 |
+
# Memilih model sentimen berdasarkan pilihan pengguna
|
99 |
+
sentiment_model = select_sentiment_model(selected_model)
|
100 |
+
|
101 |
+
|
102 |
# Fungsi untuk prediksi sentimen
|
103 |
def predict_sentiment(text, model, tfidf_vectorizer, slang_dict):
|
104 |
# Tahap-1: Membersihkan dan normalisasi teks
|
|
|
117 |
|
118 |
return sentiment_label
|
119 |
|
|
|
|
|
|
|
|
|
120 |
def get_emoticon(sentiment):
|
121 |
if sentiment == "Positif":
|
122 |
emoticon = "π" # Emotikon untuk sentimen positif
|
|
|
140 |
# Judul
|
141 |
st.title("Aplikasi ML Analisis Sentimen based on data Biskita Transpakuan")
|
142 |
|
143 |
+
# Tambahkan widget untuk memilih model
|
144 |
+
selected_model = st.selectbox("Pilih Model Sentimen:", ("Random Forest", "Ensemble", "Naive Bayes", "Logistic Regression"))
|
145 |
+
|
146 |
# Pilihan input teks manual atau berkas XLSX
|
147 |
input_option = st.radio("Pilih metode input:", ("Teks Manual", "Unggah Berkas XLSX"))
|
148 |
|