Spaces:
Running
Running
init decoded label def
Browse files
app.py
CHANGED
@@ -11,6 +11,20 @@ logistic_model = joblib.load("Logistic_Model.joblib") # Logistic
|
|
11 |
vectorizer = joblib.load("vectorizer.joblib") # global vocabulary (used for Logistic, SVC)
|
12 |
tokenizer = joblib.load("tokenizer.joblib") # used for LSTM
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
# Web Crawler function
|
15 |
def crawURL(url):
|
16 |
# Fetch the URL content
|
@@ -66,14 +80,13 @@ def process_api(text):
|
|
66 |
# padded_sequence = pad_sequences(sequence, maxlen=1000, padding='post')
|
67 |
|
68 |
# Get the predicted result from models
|
69 |
-
Logistic_Predicted = logistic_model.predict(processed_text).tolist()
|
70 |
-
SVM_Predicted = SVM_model.predict(processed_text).tolist()
|
71 |
# Seq_Predicted = Seq_model.predict(padded_sequence)
|
72 |
-
|
73 |
# predicted_label_index = np.argmax(Seq_Predicted)
|
74 |
return {
|
75 |
-
'
|
76 |
-
'
|
77 |
'Article_Content': text,
|
78 |
}
|
79 |
|
|
|
11 |
vectorizer = joblib.load("vectorizer.joblib") # global vocabulary (used for Logistic, SVC)
|
12 |
tokenizer = joblib.load("tokenizer.joblib") # used for LSTM
|
13 |
|
14 |
+
# Decode label function
|
15 |
+
# {'business': 0, 'entertainment': 1, 'health': 2, 'politics': 3, 'sport': 4}
|
16 |
+
def categorize(input_number):
|
17 |
+
categories = {
|
18 |
+
0: 'Business',
|
19 |
+
1: 'Entertainment',
|
20 |
+
2: 'Health',
|
21 |
+
3: 'Politics',
|
22 |
+
4: 'Sport'
|
23 |
+
}
|
24 |
+
result = categories.get(input_number)
|
25 |
+
print('decoded result', result)
|
26 |
+
return result
|
27 |
+
|
28 |
# Web Crawler function
|
29 |
def crawURL(url):
|
30 |
# Fetch the URL content
|
|
|
80 |
# padded_sequence = pad_sequences(sequence, maxlen=1000, padding='post')
|
81 |
|
82 |
# Get the predicted result from models
|
83 |
+
Logistic_Predicted = logistic_model.predict(processed_text).tolist() # Logistic Model
|
84 |
+
SVM_Predicted = SVM_model.predict(processed_text).tolist() # SVC Model
|
85 |
# Seq_Predicted = Seq_model.predict(padded_sequence)
|
|
|
86 |
# predicted_label_index = np.argmax(Seq_Predicted)
|
87 |
return {
|
88 |
+
'Logistic_Predicted': categorize(int(Logistic_Predicted[0]))
|
89 |
+
'SVM_Predicted': categorize(int(SVM_Predicted[0])),
|
90 |
'Article_Content': text,
|
91 |
}
|
92 |
|