An asynchronous backend API built with Django Rest Framework, Celery, and Redis that extracts text from PDFs and provides AI-powered summaries and sentiment analysis.
- About The Project
- Key Features
- Tech Stack
- Getting Started
- Running the Application (Local Development)
- API Documentation
- Deployment (Production)
- License
Insight AI is designed to process heavy document analysis tasks in the background without blocking your main API threads. By combining the robustness of Django with the asynchronous power of Celery and Redis, this API enables users to securely upload PDF documents, extract text implicitly, generate concise summaries via NLP, and perform semantic sentiment analysis on the content.
- Asynchronous Processing: Heavy AI tasks (PDF parsing, text summarizing) are offloaded to Celery workers to guarantee lightning-fast API responses.
- AI-Powered Insights: Integrates
PyPDF2for text extraction,Sumy(LexRank algorithm) for automated summarization, andTextBlobfor emotional sentiment analysis. - RESTful Architecture: Fully structured CRUD operations constructed via
ModelViewSets. - Auto-Generated Documentation: Real-time interactive API docs powered by Swagger UI (
drf-spectacular). - Granular Security: Strictly enforced object-level permissions ensure users can solely view and modify their own documents.
- Web Framework: Django & Django Rest Framework (DRF)
- Task Queue & Broker: Celery & Redis
- Database: PostgreSQL (Production) / SQLite (Development)
- AI / NLP Components: Sumy, TextBlob, NLTK
- Documentation: Swagger UI / OpenAPI 3.0
Follow these instructions to get a local copy of the project up and running.
Ensure you have the following installed on your local machine:
- Python 3.10+
- Redis Server (
sudo apt install redis-server)
-
Clone the repository
git clone https://github.com/AlisherOP/Insight.git cd Insight -
Create and activate a virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\\Scripts\\activate
-
Install the dependencies
pip install -r requirements.txt
-
Environment Variables
Create a.envfile in the root directory (wheremanage.pyis located) and add the following:DEBUG=True SECRET_KEY='your-secret-key-goes-here' CELERY_BROKER=redis://localhost:6379/0
-
Run database migrations
python manage.py migrate
To run the application locally, you need three distinct terminal windows running concurrently.
Ensure your Redis message broker is running in the background.
sudo systemctl start redis-server
# Verify it's running with: redis-cli ping (Should return PONG)Open a second terminal, activate your virtual environment, and launch the Celery worker to intercept background tasks.
celery -A Insight worker --loglevel=infoOpen a third terminal, activate your virtual environment, and launch the API.
python manage.py runserverOnce the Django development server is running, you can access the interactive Swagger UI.
- Swagger UI: http://127.0.0.1:8000/api/docs/
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/documents/ |
Upload a new PDF document for AI processing |
GET |
/api/documents/ |
List all documents belonging to the authenticated user |
GET |
/api/documents/{id}/ |
Retrieve the result of a specific analyzed document |
DELETE |
/api/documents/{id}/ |
Delete a document |
To deploy Insight AI professionally on a cloud provider (e.g., AWS, DigitalOcean, Linode), avoid using the built-in runserver. Instead, use a production-ready stack:
- Gunicorn: Serves the Django application (WSGI).
- Nginx: Acts as a reverse proxy, handling static/media files and routing requests to Gunicorn.
- Manager: Systemd / Supervisor to manage Gunicorn and Celery processes.
- PostgreSQL: Replaces the local SQLite database for handling massive concurrency safely.
- Setup PostgreSQL: Update your
DATABASESsetting insettings.pyto point to a PostgreSQL instance. Installpsycopg2-binary. - Configure Static Files: Run
python manage.py collectstaticto gather static assets for Nginx. - Turn off DEBUG Mode: In your
.envfile, critically setDEBUG=Falseand updateALLOWED_HOSTSwith your domain/IP. - Deploy Gunicorn:
pip install gunicorn gunicorn --workers 3 Insight.wsgi:application
- Daemonizing Celery: Create a Systemd service file (e.g.,
/etc/systemd/system/celery.service) to ensure your AI background tasks boot up automatically with the server and survive crashes. - Daemonizing Redis: Ensure Redis runs continuously (
sudo systemctl enable redis-server).
💡 Best Practice: Consider containerizing the application using Docker and Docker Compose. This will allow you to package Django, Celery, and Redis into separate, deployment-ready containers, eliminating environment disparities between development and production.
Distributed under the MIT License.