Project Overview
This web app provides real-time sentiment analysis of the latest posts from any subreddit (default: r/politics and r/AITA). It fetches the newest headlines via Reddit’s API, runs them through a fine-tuned DistilBERT sentiment model hosted on Hugging Face, and serves both cached and live results.
Backend: Flask, Redis (for caching), Hugging Face Inference Endpoint (DistilBERT).
Frontend: HTML/CSS/JavaScript. Deployed on Vercel.
Structure
- Fetches headlines + scores in real-time, but also caches results so users see instant data while the model warms up.
- Sentiment scores range from -1 (negative) to +1 (positive).
- Endpoints return JSON (avg, median, post-level sentiment), and pages render them dynamically.
Coolest Features
- Dynamic subreddit pages: just go to
/subreddit_name
(like /pics
) and it works out-of-the-box.
- Redis caching: stale results (up to 1h old) are served instantly while new scores are fetched in the background. This is to reduce my HuggingFace inference costs :( nothing is free in life...
- Endpoint “warm” route: pings the Hugging Face model so users don't wait through cold starts.
To Do
- Improve model accuracy with more training + fine-tuning.
- Experiment with vocab size, learning rate, optimizer settings.
- Add more visualizations: histograms of sentiment distribution, trendlines over time, etc.
Creator(s)