TruthLens is a Flask web app that analyzes article credibility using:
- A trained ML model (Logistic Regression + TF-IDF)
- Google Fact Check API lookups
- A Contact Us form with database-backed message storage
- Password reset links with one-time tokens
Contact and password reset are resilient:
- User messages are always saved to the database first.
- Email delivery uses Gmail SMTP via environment variables.
- If delivery fails, users still receive a stable success response.
- Email failure details are stored internally for diagnostics.
This means deployments can run on local SQLite or managed cloud databases.
- Python 3.10+ (recommended)
- pip
- Internet access (for optional API checks and optional SMTP mail delivery)
- Clone this repository.
- Open the project folder in VS Code.
python -m venv .venv
.\.venv\Scripts\Activate.ps1python3 -m venv .venv
source .venv/bin/activatepip install -r requirements.txt
python -m spacy download en_core_web_smCopy the example file and edit values:
Copy-Item .env.example .envcp .env.example .envRequired and optional values are documented in .env.example.
For Contact Us + Forgot Password to be fully functional in production, set:
SECRET_KEY(required)DATABASE_URL(required for shared cloud database; if omitted uses local SQLite)EMAIL(your Gmail address used to send emails)APP_PASSWORD(Gmail App Password)ADMIN_EMAILorCONTACT_RECIPIENT(where contact messages are delivered)
Optional but recommended:
FACT_CHECK_API_KEYfor Google Fact Check integration
Forgot Password now sends a 6-digit OTP to the user's registered email.
python app.pyOpen:
- Start command:
gunicorn app:app - Procfile is included with:
web: gunicorn app:app - Set environment variables in Render:
EMAILAPP_PASSWORDADMIN_EMAILCONTACT_RECIPIENTFRONTEND_ORIGIN(your Vercel domain, e.g.https://your-app.vercel.app)
- Set
API_BASE_URLto your deployed backend URL (for examplehttps://truthlens.onrender.com). - Forms for contact/forgot/reset/predict automatically route to this base URL when set.
- If your frontend uses fetch/axios, point all API calls to
${API_BASE_URL}/contact,${API_BASE_URL}/forgot-password, and${API_BASE_URL}/reset-password.
- Open Contact page.
- Submit Name + Message (Email optional).
- Confirm success message appears.
- Confirm message is stored in SQLite database at
instance/users.dbtablecontact_message.
If Gmail SMTP is configured correctly in .env:
- Contact message is saved AND email is sent.
Gmail setup:
- Enable 2-Step Verification
- Generate an App Password
- Put Gmail in
EMAILand App Password inAPP_PASSWORD
- For Render/Railway/Fly.io/Globe-like platforms, use a managed Postgres URL in
DATABASE_URL. - The app auto-detects
postgres://and converts it topostgresql://. - Local development still works with SQLite when
DATABASE_URLis unset.
- Password reset uses secure one-time OTPs valid for 10 minutes.
- OTPs are hashed before storage and invalidated after use.
If SMTP is missing or fails:
- Contact message is still saved.
- User still sees success response.
- Failure reason is captured in
email_errorin the database.
Do not commit real credentials in .env.
Use .env.example as the template and keep secrets local only.