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
Top comments (0)