Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,11 +9,11 @@ from tensorflow.keras.preprocessing.text import Tokenizer
|
|
9 |
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
10 |
|
11 |
# load all the models and vectorizer (global vocabulary)
|
12 |
-
Seq_model = load_model("LSTM.h5") # Sequential
|
13 |
SVM_model = joblib.load("SVM_Linear_Kernel.joblib") # SVM
|
14 |
logistic_model = joblib.load("Logistic_Model.joblib") # Logistic
|
15 |
vectorizer = joblib.load("vectorizer.joblib") # global vocabulary (used for Logistic, SVC)
|
16 |
-
tokenizer = joblib.load("tokenizer.joblib") # used for LSTM
|
17 |
|
18 |
# Decode label function
|
19 |
# {'business': 0, 'entertainment': 1, 'health': 2, 'politics': 3, 'sport': 4}
|
@@ -81,26 +81,26 @@ def crawURL(url):
|
|
81 |
def process_api(text):
|
82 |
# Vectorize the text data
|
83 |
processed_text = vectorizer.transform([text])
|
84 |
-
sequence = tokenizer.texts_to_sequences([text])
|
85 |
-
padded_sequence = pad_sequences(sequence, maxlen=1000, padding='post')
|
86 |
|
87 |
# Get the predicted result from models
|
88 |
Logistic_Predicted = logistic_model.predict(processed_text).tolist() # Logistic Model
|
89 |
SVM_Predicted = SVM_model.predict(processed_text).tolist() # SVC Model
|
90 |
-
Seq_Predicted = Seq_model.predict(padded_sequence)
|
91 |
# predicted_label_index = np.argmax(Seq_Predicted)
|
92 |
|
93 |
# ----------- Debug Logs -----------
|
94 |
logistic_debug = decodedLabel(int(Logistic_Predicted[0]))
|
95 |
svc_debug = decodedLabel(int(SVM_Predicted[0]))
|
96 |
-
predicted_label_index = np.argmax(Seq_Predicted)
|
97 |
print('Logistic', int(Logistic_Predicted[0]), logistic_debug)
|
98 |
print('SVM', int(SVM_Predicted[0]), svc_debug)
|
99 |
|
100 |
return {
|
101 |
'Logistic_Predicted':decodedLabel(int(Logistic_Predicted[0])),
|
102 |
'SVM_Predicted': decodedLabel(int(SVM_Predicted[0])),
|
103 |
-
'LSTM': decodedLabel(int(predicted_label_index)),
|
104 |
'Article_Content': text
|
105 |
}
|
106 |
|
@@ -209,7 +209,7 @@ if url:
|
|
209 |
st.json({
|
210 |
"Logistic": result.get("Logistic_Predicted"),
|
211 |
"SVC": result.get("SVM_Predicted"),
|
212 |
-
"LSTM": result.get("LSTM")
|
213 |
})
|
214 |
|
215 |
st.divider() # π Draws a horizontal rule
|
|
|
9 |
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
10 |
|
11 |
# load all the models and vectorizer (global vocabulary)
|
12 |
+
# Seq_model = load_model("LSTM.h5") # Sequential
|
13 |
SVM_model = joblib.load("SVM_Linear_Kernel.joblib") # SVM
|
14 |
logistic_model = joblib.load("Logistic_Model.joblib") # Logistic
|
15 |
vectorizer = joblib.load("vectorizer.joblib") # global vocabulary (used for Logistic, SVC)
|
16 |
+
# tokenizer = joblib.load("tokenizer.joblib") # used for LSTM
|
17 |
|
18 |
# Decode label function
|
19 |
# {'business': 0, 'entertainment': 1, 'health': 2, 'politics': 3, 'sport': 4}
|
|
|
81 |
def process_api(text):
|
82 |
# Vectorize the text data
|
83 |
processed_text = vectorizer.transform([text])
|
84 |
+
# sequence = tokenizer.texts_to_sequences([text])
|
85 |
+
# padded_sequence = pad_sequences(sequence, maxlen=1000, padding='post')
|
86 |
|
87 |
# Get the predicted result from models
|
88 |
Logistic_Predicted = logistic_model.predict(processed_text).tolist() # Logistic Model
|
89 |
SVM_Predicted = SVM_model.predict(processed_text).tolist() # SVC Model
|
90 |
+
# Seq_Predicted = Seq_model.predict(padded_sequence)
|
91 |
# predicted_label_index = np.argmax(Seq_Predicted)
|
92 |
|
93 |
# ----------- Debug Logs -----------
|
94 |
logistic_debug = decodedLabel(int(Logistic_Predicted[0]))
|
95 |
svc_debug = decodedLabel(int(SVM_Predicted[0]))
|
96 |
+
# predicted_label_index = np.argmax(Seq_Predicted)
|
97 |
print('Logistic', int(Logistic_Predicted[0]), logistic_debug)
|
98 |
print('SVM', int(SVM_Predicted[0]), svc_debug)
|
99 |
|
100 |
return {
|
101 |
'Logistic_Predicted':decodedLabel(int(Logistic_Predicted[0])),
|
102 |
'SVM_Predicted': decodedLabel(int(SVM_Predicted[0])),
|
103 |
+
# 'LSTM': decodedLabel(int(predicted_label_index)),
|
104 |
'Article_Content': text
|
105 |
}
|
106 |
|
|
|
209 |
st.json({
|
210 |
"Logistic": result.get("Logistic_Predicted"),
|
211 |
"SVC": result.get("SVM_Predicted"),
|
212 |
+
# "LSTM": result.get("LSTM")
|
213 |
})
|
214 |
|
215 |
st.divider() # π Draws a horizontal rule
|