News_Classifier / app.py
Mpavan45's picture
Update app.py
df257e0 verified
raw
history blame
1.28 kB
import streamlit as st
import tensorflow as tf
import pickle
import numpy as np
import pandas as pd
# Load Model
model = tf.keras.models.load_model("news_classification_rnn.h5")
# Load Preprocessing Function
with open("preprocessing.pkl", "rb") as f:
clean_text = pickle.load(f)
# Load TF-IDF Vectorizer
with open("vectorizer.pkl", "rb") as f:
vectorizer = pickle.load(f)
# Define News Categories
news_categories = ["Business", "Sci/Tech","Sports","World"]
# Streamlit UI
st.title("📰 News Classification with Simple RNN")
st.write("Enter a news headline to predict its category.")
user_input = st.text_area("Enter News Text:", "")
if st.button("Classify"):
if user_input:
# Preprocess Input
processed_text = clean_text(user_input)
# Convert text to integer sequence
text_sequence = tokenizer.texts_to_sequences([processed_text])
# Pad the sequence to match model input size
text_padded = tf.keras.preprocessing.sequence.pad_sequences(text_sequence, maxlen=100)
# Prediction
prediction = model.predict(text_padded)
category = np.argmax(prediction)
st.success(f"Predicted Category: {news_categories[category]}")
else:
st.warning("Please enter a news headline.")