Skip to content

gsaianimesh/TruthLens

Repository files navigation

🔍 TruthLens

AI-Powered Content Verification Engine

Detect AI-generated images • Identify AI-written text • Fact-check claims

Built with Next.js 16, powered by Reality Defender, Sapling AI, Groq & OpenRouter.

Next.js TypeScript TailwindCSS License: MIT


📖 About

TruthLens is a full-stack web application that verifies content authenticity using multiple AI models running in parallel. Upload an image, paste text, or enter a news headline — TruthLens will analyze it through specialized AI pipelines and return a credibility score with a detailed explanation and source citations.

No single model is trusted alone. Every verification runs through a multi-model pipeline with weighted score fusion to minimize false positives and maximize detection accuracy.


✨ Features

Feature Description
🖼️ AI Image Detection Detects AI-generated images (Midjourney, DALL·E, Stable Diffusion, etc.) using Reality Defender's deep-learning models. Large images (>5 MB) automatically fallback to Gemini 2.0 Flash vision via OpenRouter.
📝 AI Text Detection Identifies AI-generated text using Sapling AI's sentence-level detector. Includes a dual-Groq fallback (forensic + pattern analysis) when the primary detector is unavailable.
📰 Fact-Checking Cross-references news claims and headlines against trusted journalism sources using Groq's LLaMA 3.3 70B. Returns credibility ratings (LOW / MEDIUM / HIGH) with source links.
📊 Visual Results Dashboard Animated circular credibility meters, color-coded status banners, horizontal bar indicators, and detailed AI-generated explanations.
🔬 Live Analysis Pipeline Real-time stage-by-stage progress visualization with ETA countdown, elapsed timer, and image scan overlay with animated beam.
📜 Verification History All past verifications stored locally in the browser (localStorage). Browse, review, or delete individual entries.
🔒 Privacy-First Content is analyzed and discarded immediately. No user data is stored on the server.
📱 Fully Responsive Mobile-first design with hamburger navigation and adaptive layouts.

🏗️ Architecture

┌─────────────────────────────────────────────────────────────┐
│                        Frontend (Next.js)                   │
│                                                             │
│  VerificationPanel ──→ AnalysisLoader ──→ ResultDashboard   │
│  (Image/Text/News)     (Pipeline UI)      (Scores + Report) │
└─────────────────┬───────────────────────────────────────────┘
                  │ POST /api/verify/{image,text,news}
                  ▼
┌─────────────────────────────────────────────────────────────┐
│                     API Routes (Server)                      │
│                                                             │
│  ┌─── Image ──────────────────────────────────────────────┐ │
│  │ Normal: Reality Defender SDK → Groq (explanation)      │ │
│  │ Large:  OpenRouter Gemini 2.0 Flash → Groq (explain.)  │ │
│  └────────────────────────────────────────────────────────┘ │
│  ┌─── Text ───────────────────────────────────────────────┐ │
│  │ Primary: Sapling AI → Groq (explanation)               │ │
│  │ Fallback: Dual-Groq scoring (forensic + pattern)       │ │
│  └────────────────────────────────────────────────────────┘ │
│  ┌─── News ───────────────────────────────────────────────┐ │
│  │ Groq fact-check + AI text detection + Source citations  │ │
│  └────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘

🛠️ Tech Stack

Frontend

  • Next.js 16.1.6 — React framework with App Router & Turbopack
  • TypeScript 5 — Full type safety
  • TailwindCSS 4 — Utility-first styling with custom design tokens
  • Framer Motion — Smooth animations & page transitions
  • Lucide React — Consistent icon system
  • Google Fonts — Inter (body) + Space Grotesk (headings)

Backend (API Routes)

  • Reality Defender SDK — Deep-learning image authenticity detection
  • Sapling AI — Sentence-level AI text detection
  • Groq (LLaMA 3.3 70B Versatile) — Explanations, fact-checking, fallback text analysis
  • OpenRouter (Gemini 2.0 Flash) — Large image analysis fallback

📁 Project Structure

truthlens/
├── src/
│   ├── app/
│   │   ├── api/verify/
│   │   │   ├── image/route.ts      # Image verification endpoint
│   │   │   ├── text/route.ts       # Text AI detection endpoint
│   │   │   └── news/route.ts       # Fact-checking endpoint
│   │   ├── history/page.tsx         # Verification history page
│   │   ├── transparency/page.tsx    # How It Works page
│   │   ├── layout.tsx               # Root layout (fonts, metadata)
│   │   ├── page.tsx                 # Homepage (hero, panel, results)
│   │   └── globals.css              # Design system & theme tokens
│   └── components/
│       ├── Navbar.tsx               # Fixed navigation bar
│       ├── VerificationPanel.tsx    # 3-tab input (Image/Text/News)
│       ├── AnalysisLoader.tsx       # Pipeline progress visualization
│       ├── ResultDashboard.tsx      # Results with meters & explanation
│       ├── CredibilityMeter.tsx     # Animated SVG circular gauge
│       ├── SourcesPanel.tsx         # Verified source links
│       ├── HowItWorks.tsx           # Feature explanation cards
│       └── Footer.tsx               # Site footer
├── .env.local                       # API keys (not committed)
├── next.config.ts                   # Next.js config (20MB body limit)
├── package.json
└── tsconfig.json

🚀 Getting Started

Prerequisites

  • Node.js ≥ 20
  • npm (comes with Node.js)

1. Clone the repository

git clone https://github.com/gsaianimesh/TruthLens.git
cd TruthLens

2. Install dependencies

npm install

3. Configure API keys

Create a .env.local file in the project root:

REALITY_DEFENDER_API_KEY=your_reality_defender_api_key
SAPLING_API_KEY=your_sapling_api_key
GROQ_API_KEY=your_groq_api_key
OPENROUTER_API_KEY=your_openrouter_api_key
Where to get API keys
Service Sign Up Free Tier
Reality Defender Request access Limited
Sapling AI Sign up Yes
Groq Sign up Generous free tier
OpenRouter Sign up Pay-per-use

4. Run the development server

npm run dev

Open http://localhost:3000 in your browser.

5. Build for production

npm run build
npm start

🔌 API Endpoints

POST /api/verify/image

Detect if an image is AI-generated.

Request body:

{
  "image": "data:image/png;base64,...",
  "largeImage": false
}

Response:

{
  "type": "image",
  "ai_probability": 87,
  "credibility_score": 13,
  "explanation": "This image shows multiple indicators of AI generation...",
  "verified_sources": [],
  "detection_method": "reality_defender"
}

POST /api/verify/text

Detect if text is AI-written.

Request body:

{
  "text": "The quick brown fox jumps over the lazy dog..."
}

Response:

{
  "type": "text",
  "ai_probability": 94,
  "credibility_score": 6,
  "explanation": "The text exhibits strong AI-generation patterns...",
  "verified_sources": [],
  "detection_method": "sapling"
}

POST /api/verify/news

Fact-check a claim or headline.

Request body:

{
  "text": "NASA confirms the moon is shrinking by 50 meters per year"
}

Response:

{
  "type": "news",
  "ai_probability": 72,
  "credibility_score": 28,
  "claim_credibility": "LOW",
  "explanation": "While NASA has confirmed lunar shrinkage, the actual rate is...",
  "verified_sources": [
    { "title": "NASA - Shrinking Moon", "url": "https://..." }
  ]
}

🎨 Design

The UI follows a clean, dark-mode-first aesthetic inspired by Linear and Vercel:

  • Color palette: Deep black (#09090b), muted violet primary (#7c5cfc), sky accent (#38bdf8)
  • Typography: Inter for body text, Space Grotesk for headings
  • Surfaces: Subtle bordered cards with soft box shadows — no glass-morphism
  • Animations: Purposeful Framer Motion transitions, no decorative glow effects
  • Background: Minimal dot-grid pattern

🔑 Verification Pipelines — In Detail

Image Pipeline

  1. Image Upload — User drags/drops or selects an image (up to 20 MB)
  2. Size Check — If >5 MB, user sees a warning and can choose to continue (uses lighter OpenRouter model) or pick a smaller image
  3. Analysis
    • Normal path: Image saved to temp file → Reality Defender SDK detect() with 60-second timeout → AI probability score
    • Large image path: Base64 sent to OpenRouter (Gemini 2.0 Flash vision model) → AI probability score
  4. Explanation — Groq LLaMA 3.3 generates a human-readable explanation from the raw detection data
  5. Cleanup — Temp file deleted immediately after analysis

Text Pipeline

  1. Text Input — User pastes text into the editor
  2. Primary Detection — Sapling AI API analyzes the text at sentence level, returning per-sentence AI probability scores
  3. Fallback — If Sapling fails, two independent Groq analyses run in parallel:
    • Forensic analysis (60% weight): Linguistic entropy, vocabulary diversity, burstiness
    • Pattern analysis (40% weight): Structural patterns, stylistic markers, coherence
  4. Explanation — Groq generates a detailed explanation citing specific indicators found

News Pipeline

  1. Input — User enters a URL, headline, or claim
  2. Parallel Analysis — Three engines run simultaneously:
    • Groq fact-check (claim credibility against known sources)
    • AI text detection (is the article itself AI-generated?)
    • Linguistic authenticity analysis
  3. Score Fusion — Results weighted 70% fact-check, 30% AI-text detection
  4. Output — Credibility rating (LOW/MEDIUM/HIGH), explanation, and source citations

🔐 Security & Privacy

  • API keys stored in .env.local (gitignored — never committed)
  • Image data processed in-memory; temp files deleted immediately after analysis
  • No user data or submissions persisted server-side
  • Input validation on all API endpoints
  • Content-type checking for uploaded images
  • Request body size limited to 20 MB

🤝 Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/my-feature)
  3. Commit your changes (git commit -m 'Add my feature')
  4. Push to the branch (git push origin feature/my-feature)
  5. Open a Pull Request

📄 License

This project is open source under the MIT License.


Built by Animesh

Fighting misinformation with AI.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors