import streamlit as st import pandas as pd import time from transformers import pipeline # Set page title and layout st.set_page_config(page_title="CSV News Classifier", layout="wide") # Load the fine-tuned Hugging Face model @st.cache_resource def load_model(): return pipeline("text-classification", model="TAgroup5/daily-mirror-news-classifier") classifier = load_model() # Custom CSS for Colors and Styling st.markdown( """ """, unsafe_allow_html=True ) # Page Title st.title("📊 News Classification from CSV") # File Uploader st.markdown('

📂 Upload a CSV file

', unsafe_allow_html=True) uploaded_file = st.file_uploader("", type=["csv"]) if uploaded_file is not None: # Read CSV df = pd.read_csv(uploaded_file) # Show Preview st.markdown("### 🔍 **Preview of Uploaded File**", unsafe_allow_html=True) st.dataframe(df.head()) # Assuming the column with news articles is named "news_text" if "news_text" not in df.columns: st.error("❌ The uploaded CSV must contain a 'news_text' column.") else: # Perform classification st.markdown("### 🏷️ **Classifying News Articles...**") with st.spinner("Processing..."): df["class"] = df["news_text"].apply(lambda text: classifier(text)[0]["label"]) # Show Preview of Results st.markdown("### 📌 **Preview of Classified Data**", unsafe_allow_html=True) st.dataframe(df.head()) # Download Button for Classified CSV csv = df.to_csv(index=False).encode("utf-8") st.markdown("### 📥 **Download Classified CSV**", unsafe_allow_html=True) st.download_button( label="⬇️ **Download Classified CSV**", data=csv, file_name="classified_news.csv", mime="text/csv", help="Click to download the classified news file" ) # Footer st.markdown("---") st.markdown('

👨‍💻 Developed by Ridmi Navodya | Powered by Streamlit 🚀

', unsafe_allow_html=True)