Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FactifyAI

AI-Powered Fake News Detection for Indian Languages

Python FastAPI Gemini Manifest V3 Languages License: MIT

A full-stack fake news detection system combining a Chrome/Edge sidebar extension with a FastAPI backend. Uses Google Gemini AI for content analysis, SerpAPI + NewsAPI for real-time source cross-referencing, and a curated credibility database of 100+ Indian news sources across 10 languages.



✨ Key Features

🧩 Browser Extension (Manifest V3)

  • Sidebar Panel — Tabbed interface for text analysis, source checking, and image verification
  • Context Menu — Right-click selected text → "Verify with FactifyAI"
  • Auto-Detection — Detects text selection on any webpage automatically
  • Real-Time Results — Confidence scores, source cards, and credibility summaries

⚙️ Backend API (FastAPI)

  • Gemini AI Analysisgemini-2.5-flash-lite via Vertex AI, structured JSON output
  • Multi-Source Verification — SerpAPI, NewsAPI, RapidAPI, MediaStack, NewsData, GNews
  • Credibility Database — 100+ pre-scored Indian news domains across states
  • Heuristic Fallback — Clickbait/bias detection when Gemini is unavailable

🌐 Language Support

Language Code Regional Sources
English en International & Indian English media
Hindi hi Hindi News18, Indian Express Hindi, The Hindu Hindi
Telugu te Eenadu, Sakshi, Telangana Today
Tamil ta Dinamani, Dinakaran, Tamil The Hindu
Bengali bn Bengali News18, Bengali OneIndia
Gujarati gu Gujarati News18, Gujarati OneIndia
Marathi mr Marathi News18, Marathi OneIndia
Kannada kn Kannada News18, Kannada OneIndia
Malayalam ml Malayalam News18, Malayalam OneIndia
Punjabi pa Punjabi News18, Punjabi OneIndia

🏗 Architecture

How It Works

flowchart TD
    A([👤 User selects text on any webpage]) --> B

    subgraph EXT["🧩 Browser Extension (Manifest V3)"]
        B[Content script detects selection]
        C[Sidebar / Context Menu triggered]
        B --> C
    end

    C -->|POST /analyze_text| D

    subgraph API["⚙️ FastAPI Backend"]
        D[Request Router]

        subgraph SOURCES["📡 News Source APIs"]
            E[SerpAPI\nGoogle News]
            F[NewsAPI\nHeadlines]
            G[Optional APIs\nMediaStack · GNews\nNewsData · RapidAPI]
        end

        D --> E & F & G

        H[🔍 Relevance Filter\nRegional boost · Lang-aware\nExcludes spam domains]
        E & F & G --> H

        I[🏅 Source Credibility Engine\n100+ Indian domains · 10 languages\nDomain scoring]
        H --> I

        J{Gemini\nAvailable?}
        I --> J

        K[🤖 Gemini AI Analysis\ngemini-2.5-flash-lite\nText + Vision · Structured JSON]
        L[🔄 Heuristic Fallback\nScikit-learn TF-IDF\nClickbait & bias detection]

        J -- Yes --> K
        J -- No  --> L
    end

    K & L --> M

    subgraph RESP["📊 Structured Response"]
        M[Classification · Confidence\nExplanation · Verified sources\nCredibility summary · Language]
    end

    M --> N([✅ Results rendered in sidebar])

    style EXT fill:#e8f4fd,stroke:#4A90D9,stroke-width:1.5px,color:#1a1a2e
    style API fill:#f0fdf4,stroke:#22C55E,stroke-width:1.5px,color:#1a1a2e
    style SOURCES fill:#fef9c3,stroke:#EAB308,stroke-width:1px,color:#1a1a2e
    style RESP fill:#fdf4ff,stroke:#A855F7,stroke-width:1.5px,color:#1a1a2e
Loading

Image Verification Pipeline

flowchart LR
    A([🖼️ Image URL or base64]) --> B
    B[OCR Extraction\nExtract text from image] --> C
    C[Fact-Check Text\nRun through main AI pipeline] --> D
    D[Reverse Image Search\nGoogle Lens · Google Images] --> E
    E([📋 Authenticity report\nis_authentic · confidence\nsimilar_images])

    style A fill:#fdf4ff,stroke:#A855F7,stroke-width:1.5px
    style E fill:#f0fdf4,stroke:#22C55E,stroke-width:1.5px
Loading

Project Structure

FactifyAI/
├── 📂 backend/
│   ├── main.py                          # FastAPI app — endpoints & request models
│   ├── 📂 services/
│   │   ├── gemini_service.py            # Vertex AI Gemini (text + vision)
│   │   ├── serpapi_service.py           # SerpAPI news & reverse image search
│   │   ├── newsapi_service.py           # NewsAPI headlines & article search
│   │   ├── additional_apis_service.py   # RapidAPI, MediaStack, NewsData, GNews
│   │   ├── source_verification.py       # Domain credibility database & scoring
│   │   └── relevance_filter.py          # Regional language-aware source filtering
│   ├── 📂 utils/
│   │   ├── language_detector.py         # Unicode-based Indic language detection
│   │   └── text_processor.py            # Text cleaning, keyword extraction, bias detection
│   ├── 📂 models/
│   │   ├── fake_news_model.pkl          # Scikit-learn fallback model
│   │   └── vectorizer.pkl               # TF-IDF vectorizer for fallback
│   ├── requirements.txt
│   └── env.example                      # Environment variable template
├── 📂 extension/
│   ├── manifest.json                    # Manifest V3 config
│   ├── background.js                    # Service worker — context menus, messaging
│   ├── content.js                       # Content script — text selection detection
│   ├── sidebar.html                     # Sidebar panel UI
│   ├── sidebar.css                      # Sidebar styles
│   ├── sidebar.js                       # Sidebar logic — API calls, result rendering
│   └── 📂 icons/                        # Extension icons (16 / 48 / 128px + logo)
├── create_env.py                        # Helper to generate .env from template
├── start_backend.py                     # One-click backend startup script
└── test_final.py                        # API integration test script

🚀 Getting Started

Prerequisites

  • Python 3.8+
  • Chrome or Edge browser
  • API keys (see below)

1 · Clone & Install

git clone https://github.com/YOUR_USERNAME/FactifyAI.git
cd FactifyAI

# Install backend dependencies
cd backend
pip install -r requirements.txt

2 · Configure API Keys

# Option A — use the helper script (recommended)
cd ..
python create_env.py
# Then edit backend/.env with your actual keys

# Option B — copy the template manually
cp backend/env.example backend/.env
# Edit backend/.env with your keys

Required API keys:

API Purpose Get Key
Google Cloud (Gemini) AI text analysis, OCR, image analysis Google Cloud Console — Enable Vertex AI, create a Service Account, download JSON key
SerpAPI Google News search, reverse image search serpapi.com
NewsAPI News article search & headlines newsapi.org

Optional API keys (enhance accuracy with additional sources):

API Purpose Get Key
RapidAPI News aggregator rapidapi.com
MediaStack Global news feed mediastack.com
NewsData News articles newsdata.io
GNews Google News aggregator gnews.io

💡 Gemini Credentials: Place the downloaded service account JSON as backend/credentials.json, or set individual environment variables in .env. The service checks for the JSON file first and falls back to environment variables.

3 · Start the Backend

# Option A — startup script (recommended)
python start_backend.py

# Option B — run uvicorn directly
cd backend
uvicorn main:app --reload --host 0.0.0.0 --port 8000

API available at http://localhost:8000 · Interactive docs at /docs

4 · Load the Extension

  1. Open chrome://extensions/ (or edge://extensions/)
  2. Enable Developer mode
  3. Click Load unpacked → select the extension/ folder
  4. Pin the FactifyAI extension for easy access

📡 API Reference

POST /analyze_text — Analyze news text

// Request
{ "text": "News article text to analyze", "url": "https://source-url.com" }

// Response
{
  "classification": "Likely Genuine | Potentially Misleading",
  "confidence": 0.85,
  "explanation": "Detailed analysis...",
  "language": "en",
  "key_points": "Key findings...",
  "sources_found": 5,
  "verified_sources": [{ "title": "...", "domain": "...", "authenticity_score": 0.9 }],
  "credibility_summary": { "average_credibility": 0.82, "high_credibility_count": 3 }
}

POST /check_source — Check domain credibility

// Request
{ "url": "https://example.com/article" }

// Response
{
  "domain": "example.com",
  "credibility_score": 0.75,
  "assessment": "Moderately Credible",
  "details": "Analysis details...",
  "recommendations": "Cross-reference with other sources"
}

POST /reverse_image — Verify an image

// Request
{ "image_url": "https://example.com/image.jpg", "image_data": "base64..." }

// Response
{
  "status": "success",
  "analysis": "OCR + fact-check + reverse search results...",
  "extracted_text": "Text found in image...",
  "fact_check_result": { "classification": "...", "confidence": 0.8 },
  "is_authentic": true,
  "confidence": 0.85,
  "similar_images": [...]
}

Other Endpoints

Method Endpoint Description
POST /comprehensive_verification Full pipeline: text + multi-source + credibility in one request
GET /health Availability status of Gemini, SerpAPI, and NewsAPI
GET /languages List all supported languages

🛠 Tech Stack

graph LR
    A["🤖 AI Engine\nGemini 2.5 Flash Lite\nVertex AI"]
    B["⚙️ Backend\nPython · FastAPI\naiohttp · Pydantic"]
    C["📰 News APIs\nSerpAPI · NewsAPI\nRapidAPI · MediaStack\nNewsData · GNews"]
    D["🔤 NLP\nUnicode Indic detection\nRegex text processing"]
    E["🧠 ML Fallback\nscikit-learn\nTF-IDF + Classifier"]
    F["🧩 Extension\nManifest V3\nSide Panel API\nService Workers"]
    G["🔐 Auth\nGoogle Service Account\nOAuth2"]

    B --> A
    B --> C
    B --> D
    B --> E
    F --> B
    G --> A

    style A fill:#e8f4fd,stroke:#4285F4,stroke-width:1.5px
    style B fill:#f0fdf4,stroke:#22C55E,stroke-width:1.5px
    style C fill:#fef9c3,stroke:#EAB308,stroke-width:1.5px
    style D fill:#fdf4ff,stroke:#A855F7,stroke-width:1.5px
    style E fill:#fff7ed,stroke:#F97316,stroke-width:1.5px
    style F fill:#f0f9ff,stroke:#0EA5E9,stroke-width:1.5px
    style G fill:#fef2f2,stroke:#EF4444,stroke-width:1.5px
Loading

Made with ❤️ for India's multilingual internet

About

A comprehensive fake news detection system supporting Indian vernacular languages.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages