Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,8 +12,9 @@ with open("preprocessing.pkl", "rb") as f:
|
|
| 12 |
clean_text = pickle.load(f)
|
| 13 |
|
| 14 |
# Load TF-IDF Vectorizer
|
| 15 |
-
with open("
|
| 16 |
-
vectorizer = pickle.load(f)
|
|
|
|
| 17 |
import tensorflow as tf
|
| 18 |
import pickle
|
| 19 |
import numpy as np
|
|
@@ -31,10 +32,10 @@ with open("vectorizer.pkl", "rb") as f:
|
|
| 31 |
vectorizer = pickle.load(f)
|
| 32 |
|
| 33 |
# Define News Categories
|
| 34 |
-
news_categories = ["
|
| 35 |
|
| 36 |
# Streamlit UI
|
| 37 |
-
st.title("📰 News Classification with Simple RNN
|
| 38 |
st.write("Enter a news headline to predict its category.")
|
| 39 |
|
| 40 |
user_input = st.text_area("Enter News Text:", "")
|
|
@@ -44,39 +45,16 @@ if st.button("Classify"):
|
|
| 44 |
# Preprocess Input
|
| 45 |
processed_text = clean_text(user_input)
|
| 46 |
|
| 47 |
-
# Convert text to
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
# Prediction
|
| 51 |
-
prediction = model.predict(text_vector)
|
| 52 |
-
category = np.argmax(prediction)
|
| 53 |
-
|
| 54 |
-
st.success(f"Predicted Category: {news_categories[category]}")
|
| 55 |
-
else:
|
| 56 |
-
st.warning("Please enter a news headline.")
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
# Define News Categories
|
| 60 |
-
news_categories = ["World", "Sports", "Business", "Sci/Tech"]
|
| 61 |
-
|
| 62 |
-
# Streamlit UI
|
| 63 |
-
st.title("📰 News Classification with Simple RNN + TF-IDF")
|
| 64 |
-
st.write("Enter a news headline to predict its category.")
|
| 65 |
-
|
| 66 |
-
user_input = st.text_area("Enter News Text:", "")
|
| 67 |
-
|
| 68 |
-
if st.button("Classify"):
|
| 69 |
-
if user_input:
|
| 70 |
-
# Preprocess Input
|
| 71 |
-
processed_text = clean_text(user_input)
|
| 72 |
|
| 73 |
-
#
|
| 74 |
-
|
| 75 |
|
| 76 |
# Prediction
|
| 77 |
-
prediction = model.predict(
|
| 78 |
category = np.argmax(prediction)
|
| 79 |
|
| 80 |
st.success(f"Predicted Category: {news_categories[category]}")
|
| 81 |
else:
|
| 82 |
-
st.warning("Please enter a news headline.")
|
|
|
|
| 12 |
clean_text = pickle.load(f)
|
| 13 |
|
| 14 |
# Load TF-IDF Vectorizer
|
| 15 |
+
with open("text_vectorizer.pkl", "rb") as f:
|
| 16 |
+
vectorizer = pickle.load(f)
|
| 17 |
+
import streamlit as st
|
| 18 |
import tensorflow as tf
|
| 19 |
import pickle
|
| 20 |
import numpy as np
|
|
|
|
| 32 |
vectorizer = pickle.load(f)
|
| 33 |
|
| 34 |
# Define News Categories
|
| 35 |
+
news_categories = ["Business", "Sci/Tech","Sports","World"]
|
| 36 |
|
| 37 |
# Streamlit UI
|
| 38 |
+
st.title("📰 News Classification with Simple RNN")
|
| 39 |
st.write("Enter a news headline to predict its category.")
|
| 40 |
|
| 41 |
user_input = st.text_area("Enter News Text:", "")
|
|
|
|
| 45 |
# Preprocess Input
|
| 46 |
processed_text = clean_text(user_input)
|
| 47 |
|
| 48 |
+
# Convert text to integer sequence
|
| 49 |
+
text_sequence = tokenizer.texts_to_sequences([processed_text])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
# Pad the sequence to match model input size
|
| 52 |
+
text_padded = tf.keras.preprocessing.sequence.pad_sequences(text_sequence, maxlen=100)
|
| 53 |
|
| 54 |
# Prediction
|
| 55 |
+
prediction = model.predict(text_padded)
|
| 56 |
category = np.argmax(prediction)
|
| 57 |
|
| 58 |
st.success(f"Predicted Category: {news_categories[category]}")
|
| 59 |
else:
|
| 60 |
+
st.warning("Please enter a news headline.")
|