Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,7 @@ nltk.download('stopwords')
|
|
| 17 |
lemmatizer = WordNetLemmatizer()
|
| 18 |
stop_words = set(stopwords.words('english'))
|
| 19 |
|
|
|
|
| 20 |
def pre_process(text):
|
| 21 |
text = text.lower()
|
| 22 |
text = re.sub("<.*?>", "", text)
|
|
@@ -31,15 +32,23 @@ def pre_process(text):
|
|
| 31 |
words = [lemmatizer.lemmatize(word) for word in words if word not in stop_words]
|
| 32 |
return " ".join(words)
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
label_encoder
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
def predict_category(text):
|
| 45 |
processed_text = [pre_process(text)]
|
|
@@ -59,4 +68,4 @@ if st.button("Predict Category"):
|
|
| 59 |
category = predict_category(user_text)
|
| 60 |
st.success(f"Predicted Category: {category}")
|
| 61 |
else:
|
| 62 |
-
st.warning("Please enter some text to classify.")
|
|
|
|
| 17 |
lemmatizer = WordNetLemmatizer()
|
| 18 |
stop_words = set(stopwords.words('english'))
|
| 19 |
|
| 20 |
+
@st.cache_data
|
| 21 |
def pre_process(text):
|
| 22 |
text = text.lower()
|
| 23 |
text = re.sub("<.*?>", "", text)
|
|
|
|
| 32 |
words = [lemmatizer.lemmatize(word) for word in words if word not in stop_words]
|
| 33 |
return " ".join(words)
|
| 34 |
|
| 35 |
+
@st.cache_resource
|
| 36 |
+
def load_label_encoder():
|
| 37 |
+
with open("label_encoder.pkl", "rb") as f:
|
| 38 |
+
return pickle.load(f)
|
| 39 |
|
| 40 |
+
@st.cache_resource
|
| 41 |
+
def load_text_vectorizer():
|
| 42 |
+
return tf.keras.models.load_model("news_tv_model.keras")
|
| 43 |
|
| 44 |
+
@st.cache_resource
|
| 45 |
+
def load_news_model():
|
| 46 |
+
return tf.keras.models.load_model("news_model.keras")
|
| 47 |
+
|
| 48 |
+
# Load resources
|
| 49 |
+
label_encoder = load_label_encoder()
|
| 50 |
+
text_vectorizer = load_text_vectorizer()
|
| 51 |
+
news_model = load_news_model()
|
| 52 |
|
| 53 |
def predict_category(text):
|
| 54 |
processed_text = [pre_process(text)]
|
|
|
|
| 68 |
category = predict_category(user_text)
|
| 69 |
st.success(f"Predicted Category: {category}")
|
| 70 |
else:
|
| 71 |
+
st.warning("Please enter some text to classify.")
|