Ginidu2003 commited on
Commit
8ef9c08
·
verified ·
1 Parent(s): 75ac2d1

Delete streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +0 -80
streamlit_app.py DELETED
@@ -1,80 +0,0 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import torch
4
- from transformers import pipeline
5
- import nltk
6
- from nltk.corpus import stopwords
7
- from nltk.stem import WordNetLemmatizer
8
- import re
9
- import string
10
-
11
- import os
12
- from huggingface_hub import login
13
-
14
- hf_token = os.getenv("HF_TOKEN")
15
- if hf_token:
16
- login(hf_token)
17
-
18
- # ====================== PREPROCESSING (Same as Task 2) ======================
19
-
20
- # ====================== LOAD FINE-TUNED MODEL ======================
21
- @st.cache_resource
22
- def load_model():
23
- model_name = "Ginidu2003/Distilbert-Base-News-classifier" # ← Your exact model name
24
- return pipeline(
25
- "text-classification",
26
- model=model_name,
27
- device=0 if torch.cuda.is_available() else -1
28
- )
29
-
30
- classifier = load_model()
31
-
32
- # ====================== STREAMLIT APP ======================
33
- st.title("📰 Daily Mirror News Classifier")
34
- st.subheader("Classify news into Business, Opinion, Political Gossip, Sports, or World News")
35
-
36
- st.markdown("**Upload a CSV file** with a column named `content`")
37
-
38
- uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"])
39
-
40
- if uploaded_file is not None:
41
- df = pd.read_csv(uploaded_file)
42
-
43
- st.write("### Preview of uploaded data")
44
- st.dataframe(df.head())
45
-
46
- if 'content' not in df.columns:
47
- st.error("Your CSV must have a column named 'content'")
48
- else:
49
- with st.spinner("Preprocessing and classifying..."):
50
- # Apply same preprocessing as Task 2
51
- #df['clean_content'] = df['content'].apply(preprocess_text)
52
-
53
- # Classify
54
- predictions = []
55
- for text in df['content']:
56
- if text.strip() == "":
57
- predictions.append("Unknown")
58
- else:
59
- result = classifier(text)[0]
60
- predictions.append(result['label'])
61
-
62
- df['class'] = predictions
63
-
64
- # Drop helper column
65
- #df = df.drop(columns=['clean_content'], errors='ignore')
66
-
67
- st.success("✅ Classification completed!")
68
- st.write("### Preview of classified data")
69
- st.dataframe(df.head())
70
-
71
- # Download button
72
- csv = df.to_csv(index=False).encode('utf-8')
73
- st.download_button(
74
- label="📥 Download output.csv",
75
- data=csv,
76
- file_name="output.csv",
77
- mime="text/csv"
78
- )
79
-
80
- st.caption("Built for Text Analytics Assignment - Section 02")