Tags: #python
#flask
#machinelearning
#webdev
#project
“In a world full of noise, let’s teach machines to detect the lies.”
Hey folks! 👋
In this post, I’ll walk you through how I built and deployed a Fake News Detector using Python, Flask, and Machine Learning — and hosted it online for free. Whether you're a student, a beginner developer, or just someone who loves real news 😄 — this one’s for you!
🧠 What I Built
I created a web app that allows users to paste a news article, and it predicts whether the article is real or fake using a trained machine learning model. Simple UI, clean prediction logic, and completely self-contained.
🔧 Tech Stack
- Python 3
- Flask (for the web app)
- Scikit-learn (for ML model)
- NLTK (for text preprocessing)
- HTML/CSS (for frontend)
- Render.com (for free hosting)
📁 Project Structure
project/
│
├── app.py # Flask app
├── train_model.py # ML training script
├── requirements.txt
├── /data # True.csv, Fake.csv
├── /models # Saved .pkl model + vectorizer
├── /templates/index.html # UI
├── /static/style.css # Basic CSS
├── /utils/text_cleaner.py # Text preprocessing
└── README.md
🧪 How It Works
1. Model Training
In train_model.py
:
- I combined real and fake news datasets
- Preprocessed the text (lowercase, remove stopwords, lemmatize)
- Used TF-IDF vectorization
- Trained a Logistic Regression model
- Saved the model and vectorizer with
pickle
2. The Flask Web App
In app.py
:
- Loads the model and vectorizer
- Takes user input from a text box
- Preprocesses the input using the same
clean_text()
function - Predicts using the trained model
- Displays: ✅ Real News or ❌ Fake News
🌐 Hosting It for Free with Render
Step-by-Step:
- Pushed code to GitHub
- Signed in at Render.com
- Chose New Web Service > Linked GitHub repo
- Set:
- Runtime: Python
- Start Command:
gunicorn app:app
- Done! Got a live public URL
👉 Example: https://fake-news-detector.onrender.com
📦 Dependencies (requirements.txt
)
flask
scikit-learn
nltk
pandas
gunicorn
🙌 Final Thoughts
I learned a lot through this project — from building a clean Flask UI, to saving/loading ML models, to deploying with ease.
If you're looking for a project that combines web development + machine learning and is hosted for free, this is perfect. 🔥
💬 Let’s Connect
Have questions or suggestions?
Drop a comment or reach out to me on GitHub / X — I’d love to see your version of this project!
⭐ Bonus: Want the Code?
Check it out here:
👉 GitHub Repo