Skip to content

Eric-xin/neutralize_backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Neutralize

Neutralize Icon

Neutralize

This is the backend repository for Neutralize. This project was developed during the HackIreland hackathon. And it was awarded the Runner-up prize. πŸŽ‰

This repository is no longer maintained after the completion of hackathon. For more information, see the Note section.

In today's digital age, encountering biased information is almost inevitable. To address this challenge, we developed Neutralize, a Chrome extension designed to help users identify and understand biases in the articles they read. By offering both quick insights and in-depth analyses, Neutralize empowers users to approach information critically and make informed decisions.

Features

  • Instant Bias Detection: As you browse, Neutralize analyzes the content of each webpage, providing an immediate assessment of its biasβ€”left, center, or right.
  • Alternative Perspectives: For every article, Neutralize suggests alternative sources covering the same topic, allowing users to explore diverse viewpoints.
  • Reinforcement Learning: By labeling articles, users contribute to the continuous improvement of our Natural Language Processing (NLP) model, enhancing its accuracy over time.
  • Premium GPT Analysis: For users seeking a deeper understanding, Neutralize offers a premium feature that utilizes OpenAI's GPT model to provide comprehensive bias analyses.

Note

This repository is no longer maintained after the completion of hackathon.

The new repository Neutralise-backend can be found here New features include:

  • MongoDB integration
  • Encrypted user api
  • Signup with access control and rate limit
  • Modularized endpoints
  • Improved readability and maintainability
  • Cache functionality
  • Credit check for users
  • Multicontext analysis
  • Cache-integrated api Other features like local language model, video analysis, and more are coming soon.

Table of Contents

Features

  • User Authentication: Register, login, and manage user accounts.
  • Bias Detection: Analyze text for political bias using NLP model.
  • Bias Explanation: Generate explanations for detected bias using OpenAI's GPT.
  • Database Integration: Store and manage user data using SQLite.
  • API Endpoints: Expose functionalities through RESTful API endpoints.
  • Multimodal Analysis: Analyze text and image for bias with multiple contexts.

Technologies

Python FastAPI SQLite Pydantic SQLAlchemy BERT CLIP GPT-2 OAuth2 OpenAI Transformer

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/neutralize.git
    cd neutralize
  2. Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  3. Install dependencies:

    pip install -r requirements.txt
  4. Set up environment variables:

    • Copy .env.example to .env and fill in the required values.
  5. Initialize the database:

    python database/db_gen.py

Usage

  1. Run the server:

    uvicorn server:app --reload --host 0.0.0.0 --port 9999
  2. Access the API documentation:

    • Open your browser and navigate to http://localhost:8000/api/docs.
  3. Run in development

    • Run the server with the following command:
    fastapi dev server.py

API Endpoints

Authentication

  • Register a new user:

    • POST /api/register
    • Request body: User schema
  • Login:

    • POST /api/login
    • Request body: OAuth2PasswordRequestForm

User Management

  • Retrieve all users:

    • GET /api/users
    • Response: List of UserResponse schema
  • Retrieve a single user:

    • GET /api/user/{id}
    • Response: UserResponse schema
  • Update user data:

    • PATCH /api/user/{id}
    • Request body: User schema
  • Delete a user:

    • DELETE /api/user/{id}
    • Response: List of UserResponse schema

Neutralise

  • Analyze text for bias:

    • POST /api/analyze/
    • Request body: TextRequest schema
    • Response: Bias analysis result
  • Analyze text for bias and get explanation:

    • POST /api/analyze_mult/
    • Request body: TextRequest schema
    • Response: Bias analysis result and explanation
  • Reduce bias in text:

    • POST /api/reduce_bias_txt
    • Request body: TextRequest schema
    • Response: Original text, bias analysis result, and neutralized text
  • Reduce bias in text and image:

    • POST /api/reduce_bias
    • Request body: Form data with text and optional image file
    • Response: Original text, bias analysis result, neutralized text, and additional context
  • Analyze text and image for bias with multicontext:

    • POST /api/multicon_bias_ana
    • Request body: Form data with text and optional image file
    • Response: Original text, bias analysis result, and explanation
  • Caching integration for websites visited:

    • POST /api/cache
    • Request body: CacheRequest schema
    • Response: URL, Title, and Text are added into table Cache

Technologies

  • FastAPI: Web framework for building APIs with Python.
  • Pydantic: Data validation and parsing using Python type hints.
  • SQLAlchemy: SQL toolkit and Object-Relational Mapping (ORM) for Python.
  • SQLite: Serverless, self-contained SQL database engine.
  • BERT: Pre-trained NLP model developed by Google.
  • CLIP: Vision-language multimodal model developed by OpenAI.
  • GPT-2: Generative Pre-trained Transformer developed by OpenAI.
  • OAuth2: Authentication framework for securing APIs.

Project Structure

.
β”œβ”€β”€ CRUD
β”‚Β Β  └── authen.py
β”œβ”€β”€ LICENSE
β”œβ”€β”€ assets
β”‚Β Β  └── img
β”œβ”€β”€ database.py
β”œβ”€β”€ db
β”‚Β Β  β”œβ”€β”€ SQLite.db
β”‚Β Β  β”œβ”€β”€ SQLite.db-journal
β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”œβ”€β”€ credit_check.py
β”‚Β Β  β”œβ”€β”€ db_gen.py
β”‚Β Β  └── url_cache.py
β”œβ”€β”€ models.py
β”œβ”€β”€ neutralize
β”‚Β Β  β”œβ”€β”€ NLP
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ GPT_ana.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  └── multimo.py
β”‚Β Β  β”œβ”€β”€ neutralize.py
β”‚Β Β  β”œβ”€β”€ neutralize_not_enc.py
β”‚Β Β  └── reinforced
β”‚Β Β      β”œβ”€β”€ __init__.py
β”‚Β Β      └── nlp_model.py
β”œβ”€β”€ readme.md
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ schemas.py
β”œβ”€β”€ server.py
β”œβ”€β”€ service
β”‚Β Β  β”œβ”€β”€ hashing.py
β”‚Β Β  β”œβ”€β”€ jwttoken.py
β”‚Β Β  └── oauth.py
└── uploaded_images

License

LICENSE

About

HackIreland 2025 Team 11

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages