How omspatil/news-classifier works
Project type and purpose
• This is a full-stack web application built in Python using Flask.
• Purpose: allow users to input news URLs or raw text, scrape/parse the article, classify it as real or fake with a pre-trained scikit-learn model, show the result, record query history, and accept feedback.
File structure
Top-level items:
• app.py – Flask application entry point and controller logic
• New Preditor/ – data folder (Fake.csv, True.csv), sample texts (fake_news.txt, true_news.txt), images, plus the Jinja templates and static assets for the UI
• README.md – project overview
• (Note: README refers to a models/ directory containing classifier.pkl)
Inside New Preditor/:
• Data/ – CSVs of labeled news examples; likely used for retraining or feedback persistence
• static/ – styles.css for the frontend
• templates/ – index.html Jinja template
• Images/ – UI screenshots
• fake_news.txt / true_news.txt – sample text inputs
Key components & interactions
a. Client (Browser)
• Renders the HTML/CSS (index.html + styles.css)
• Sends HTTP POST requests with URL or text payload when user clicks “Predict”
• Displays prediction results and history UI
b. Flask Backend (app.py)
• Routes:
• GET “/” → serves index.html
• POST “/predict” → handles input, orchestrates scraping, classification, history update
• GET/POST “/history” → returns or manages past queries
• POST “/feedback” → records user feedback
• Uses Beautiful Soup + requests to fetch & parse article from a URL
• Loads pre-trained scikit-learn model (classifier.pkl) to predict
• Persists query details & feedback to Data/Fake.csv or Data/True.csv (or other storage)
c. ML Model Store
• classifier.pkl – pre-trained model file on disk
• Loaded once at startup by app.py
d. Data Storage
• CSV files under New Preditor/Data – used for history & feedback
• ASCII text files (fake_news.txt, true_news.txt) for testing or training samples
e. External Services
• Internet (news websites) via HTTP requests for scraping
• (Optionally) any logging/monitoring or future DB
Architectural patterns & design principles
• MVC-ish:
• Model: ML model + data CSVs
• View: Jinja2 templates + static CSS
• Controller: Flask routes in app.py
• Single process monolith with clear separation of concerns
• Dependency injection principle: load model at startup, reuse for all predictions
• Stateless request handling; small stateful CSV appends for history