Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,13 +10,13 @@ from tensorflow.keras.preprocessing.sequence import pad_sequences
|
|
10 |
import numpy as np
|
11 |
|
12 |
# load all the models and vectorizer (global vocabulary)
|
13 |
-
|
14 |
SVM_model = joblib.load("SVM_Linear_Kernel.joblib") # SVM
|
15 |
logistic_model = joblib.load("Logistic_Model.joblib") # Logistic
|
16 |
svm_model = joblib.load('svm_model.joblib')
|
17 |
|
18 |
vectorizer = joblib.load("vectorizer.joblib") # global vocabulary (used for Logistic, SVC)
|
19 |
-
|
20 |
|
21 |
# Decode label function
|
22 |
# {'business': 0, 'entertainment': 1, 'health': 2, 'politics': 3, 'sport': 4}
|
@@ -90,21 +90,23 @@ def process_api(text):
|
|
90 |
# Get the predicted result from models
|
91 |
Logistic_Predicted = logistic_model.predict(processed_text).tolist() # Logistic Model
|
92 |
SVM_Predicted = SVM_model.predict(processed_text).tolist() # SVC Model
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
96 |
# ----------- Proba -----------
|
97 |
Logistic_Predicted_proba = logistic_model.predict_proba(processed_text)
|
98 |
-
print(float(np.max(Logistic_Predicted_proba)))
|
99 |
svm_new_probs = SVM_model.decision_function(processed_text)
|
100 |
svm_probs = svm_model.predict_proba(svm_new_probs)
|
101 |
-
print(float(np.max(svm_probs)))
|
|
|
102 |
# ----------- Debug Logs -----------
|
103 |
logistic_debug = decodedLabel(int(Logistic_Predicted[0]))
|
104 |
svc_debug = decodedLabel(int(SVM_Predicted[0]))
|
105 |
# predicted_label_index = np.argmax(Seq_Predicted)
|
106 |
-
print('Logistic', int(Logistic_Predicted[0]), logistic_debug)
|
107 |
-
print('SVM', int(SVM_Predicted[0]), svc_debug)
|
108 |
|
109 |
return {
|
110 |
'predicted_label_logistic': decodedLabel(int(Logistic_Predicted[0])),
|
@@ -112,7 +114,7 @@ def process_api(text):
|
|
112 |
|
113 |
'predicted_label_svm': decodedLabel(int(SVM_Predicted[0])),
|
114 |
'probability_svm': f"{int(float(np.max(svm_probs))*10000//100)}%",
|
115 |
-
|
116 |
'Article_Content': text
|
117 |
}
|
118 |
|
@@ -227,7 +229,7 @@ if url:
|
|
227 |
"predicted_label": result.get("predicted_label_svm"),
|
228 |
"probability": result.get("probability_svm")
|
229 |
},
|
230 |
-
|
231 |
})
|
232 |
|
233 |
st.divider() # π Draws a horizontal rule
|
|
|
10 |
import numpy as np
|
11 |
|
12 |
# load all the models and vectorizer (global vocabulary)
|
13 |
+
Seq_model = load_model("LSTM.h5") # Sequential
|
14 |
SVM_model = joblib.load("SVM_Linear_Kernel.joblib") # SVM
|
15 |
logistic_model = joblib.load("Logistic_Model.joblib") # Logistic
|
16 |
svm_model = joblib.load('svm_model.joblib')
|
17 |
|
18 |
vectorizer = joblib.load("vectorizer.joblib") # global vocabulary (used for Logistic, SVC)
|
19 |
+
tokenizer = joblib.load("tokenizer.joblib") # used for LSTM
|
20 |
|
21 |
# Decode label function
|
22 |
# {'business': 0, 'entertainment': 1, 'health': 2, 'politics': 3, 'sport': 4}
|
|
|
90 |
# Get the predicted result from models
|
91 |
Logistic_Predicted = logistic_model.predict(processed_text).tolist() # Logistic Model
|
92 |
SVM_Predicted = SVM_model.predict(processed_text).tolist() # SVC Model
|
93 |
+
Seq_Predicted = Seq_model.predict(padded_sequence)
|
94 |
+
predicted_label_index = np.argmax(Seq_Predicted)
|
95 |
+
print(int(predicted_label_index))
|
96 |
+
|
97 |
# ----------- Proba -----------
|
98 |
Logistic_Predicted_proba = logistic_model.predict_proba(processed_text)
|
99 |
+
#print(float(np.max(Logistic_Predicted_proba)))
|
100 |
svm_new_probs = SVM_model.decision_function(processed_text)
|
101 |
svm_probs = svm_model.predict_proba(svm_new_probs)
|
102 |
+
#print(float(np.max(svm_probs)))
|
103 |
+
|
104 |
# ----------- Debug Logs -----------
|
105 |
logistic_debug = decodedLabel(int(Logistic_Predicted[0]))
|
106 |
svc_debug = decodedLabel(int(SVM_Predicted[0]))
|
107 |
# predicted_label_index = np.argmax(Seq_Predicted)
|
108 |
+
#print('Logistic', int(Logistic_Predicted[0]), logistic_debug)
|
109 |
+
#print('SVM', int(SVM_Predicted[0]), svc_debug)
|
110 |
|
111 |
return {
|
112 |
'predicted_label_logistic': decodedLabel(int(Logistic_Predicted[0])),
|
|
|
114 |
|
115 |
'predicted_label_svm': decodedLabel(int(SVM_Predicted[0])),
|
116 |
'probability_svm': f"{int(float(np.max(svm_probs))*10000//100)}%",
|
117 |
+
'LSTM': decodedLabel(int(predicted_label_index)),
|
118 |
'Article_Content': text
|
119 |
}
|
120 |
|
|
|
229 |
"predicted_label": result.get("predicted_label_svm"),
|
230 |
"probability": result.get("probability_svm")
|
231 |
},
|
232 |
+
"LSTM": result.get("LSTM")
|
233 |
})
|
234 |
|
235 |
st.divider() # π Draws a horizontal rule
|