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.
- 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.
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.
- 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.
-
Clone the repository:
git clone https://github.com/yourusername/neutralize.git cd neutralize -
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
- Copy
.env.exampleto.envand fill in the required values.
- Copy
-
Initialize the database:
python database/db_gen.py
-
Run the server:
uvicorn server:app --reload --host 0.0.0.0 --port 9999
-
Access the API documentation:
- Open your browser and navigate to
http://localhost:8000/api/docs.
- Open your browser and navigate to
-
Run in development
- Run the server with the following command:
fastapi dev server.py
-
Register a new user:
POST /api/register- Request body: User schema
-
Login:
POST /api/login- Request body: OAuth2PasswordRequestForm
-
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
-
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
- 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.
.
βββ 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
