Spaces:
Sleeping
Sleeping
File size: 1,235 Bytes
5b49530 c8c9751 5b49530 9835fcd c8c9751 9835fcd fd77546 5b49530 c8c9751 1bf9b15 5b49530 fd77546 5b49530 1ef0a3c 5b49530 fd77546 c8c9751 fd77546 5b49530 c8c9751 5b49530 c8c9751 fd77546 5b49530 c8c9751 fd77546 5b49530 fd77546 39d538b fd77546 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import streamlit as st
import tensorflow as tf
import numpy as np
# Load the trained model
model = tf.keras.models.load_model("news_classification_rnn.h5")
# Load Preprocessing Function
import dill
with open("preprocessing1.pkl", "rb") as f:
clean_text = dill.load(f)
# Load Text Vectorization Layer from SavedModel
vectorizer = tf.saved_model.load("vectorizer")
# 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.strip():
# Preprocess input
processed_text = clean_text(user_input)
# Convert text to integer sequence
text_sequence = vectorizer([processed_text])
# Convert to numpy array (model expects batch input)
text_sequence = np.array(text_sequence)
# Predict Category
prediction = model.predict(text_sequence)
category = np.argmax(prediction)
st.success(f"Predicted Category: **{news_categories[category]}**")
else:
st.warning("⚠ Please enter a news headline.")
|