Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,11 +6,11 @@ from bs4 import BeautifulSoup
|
|
6 |
from datetime import date
|
7 |
|
8 |
# load all the models and vectorizer (global vocabulary)
|
9 |
-
|
10 |
SVM_model = joblib.load("SVM_Linear_Kernel.joblib") # SVM
|
11 |
logistic_model = joblib.load("Logistic_Model.joblib") # Logistic
|
12 |
vectorizer = joblib.load("vectorizer.joblib") # global vocabulary (used for Logistic, SVC)
|
13 |
-
|
14 |
|
15 |
# Decode label function
|
16 |
# {'business': 0, 'entertainment': 1, 'health': 2, 'politics': 3, 'sport': 4}
|
@@ -78,24 +78,26 @@ def crawURL(url):
|
|
78 |
def process_api(text):
|
79 |
# Vectorize the text data
|
80 |
processed_text = vectorizer.transform([text])
|
81 |
-
|
82 |
-
|
83 |
|
84 |
# Get the predicted result from models
|
85 |
Logistic_Predicted = logistic_model.predict(processed_text).tolist() # Logistic Model
|
86 |
SVM_Predicted = SVM_model.predict(processed_text).tolist() # SVC Model
|
87 |
-
|
88 |
# predicted_label_index = np.argmax(Seq_Predicted)
|
89 |
|
90 |
# ----------- Debug Logs -----------
|
91 |
logistic_debug = decodedLabel(int(Logistic_Predicted[0]))
|
92 |
svc_debug = decodedLabel(int(SVM_Predicted[0]))
|
|
|
93 |
print('Logistic', int(Logistic_Predicted[0]), logistic_debug)
|
94 |
print('SVM', int(SVM_Predicted[0]), svc_debug)
|
95 |
|
96 |
return {
|
97 |
'Logistic_Predicted':decodedLabel(int(Logistic_Predicted[0])),
|
98 |
'SVM_Predicted': decodedLabel(int(SVM_Predicted[0])),
|
|
|
99 |
'Article_Content': text
|
100 |
}
|
101 |
|
|
|
6 |
from datetime import date
|
7 |
|
8 |
# load all the models and vectorizer (global vocabulary)
|
9 |
+
Seq_model = load_model("LSTM.h5") # Sequential
|
10 |
SVM_model = joblib.load("SVM_Linear_Kernel.joblib") # SVM
|
11 |
logistic_model = joblib.load("Logistic_Model.joblib") # Logistic
|
12 |
vectorizer = joblib.load("vectorizer.joblib") # global vocabulary (used for Logistic, SVC)
|
13 |
+
tokenizer = joblib.load("tokenizer.joblib") # used for LSTM
|
14 |
|
15 |
# Decode label function
|
16 |
# {'business': 0, 'entertainment': 1, 'health': 2, 'politics': 3, 'sport': 4}
|
|
|
78 |
def process_api(text):
|
79 |
# Vectorize the text data
|
80 |
processed_text = vectorizer.transform([text])
|
81 |
+
sequence = tokenizer.texts_to_sequences([text])
|
82 |
+
padded_sequence = pad_sequences(sequence, maxlen=1000, padding='post')
|
83 |
|
84 |
# Get the predicted result from models
|
85 |
Logistic_Predicted = logistic_model.predict(processed_text).tolist() # Logistic Model
|
86 |
SVM_Predicted = SVM_model.predict(processed_text).tolist() # SVC Model
|
87 |
+
Seq_Predicted = Seq_model.predict(padded_sequence)
|
88 |
# predicted_label_index = np.argmax(Seq_Predicted)
|
89 |
|
90 |
# ----------- Debug Logs -----------
|
91 |
logistic_debug = decodedLabel(int(Logistic_Predicted[0]))
|
92 |
svc_debug = decodedLabel(int(SVM_Predicted[0]))
|
93 |
+
predicted_label_index = np.argmax(Seq_Predicted)
|
94 |
print('Logistic', int(Logistic_Predicted[0]), logistic_debug)
|
95 |
print('SVM', int(SVM_Predicted[0]), svc_debug)
|
96 |
|
97 |
return {
|
98 |
'Logistic_Predicted':decodedLabel(int(Logistic_Predicted[0])),
|
99 |
'SVM_Predicted': decodedLabel(int(SVM_Predicted[0])),
|
100 |
+
'LSTM': decodedLabel(int(predicted_label_index)),
|
101 |
'Article_Content': text
|
102 |
}
|
103 |
|