This project is a simple web application that uses AWS Comprehend to perform sentiment analysis on user-provided text. The application is built using Django, Django REST framework, and AWS Comprehend.
- sentiment_analysis/
- api/
- init.py
- admin.py
- apps.py
- migrations/
- init.py
- models.py
- tests.py
- views.py
- urls.py
- sentiment_analysis/
- init.py
- asgi.py
- settings.py
- urls.py
- views.py
- wsgi.py
- templates/
- index.html
- manage.py
- db.sqlite3
- api/
- Python 3.x
- Django
- Django REST framework
- AWS account with access to Comprehend
- Boto3
-
Clone the repository:
git clone https://github.com/yourusername/sentiment_analysis.git cd sentiment_analysis -
Create a virtual environment and activate it:
python3 -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install django djangorestframework boto3
-
Set up AWS credentials:
Configure your AWS credentials by running:
aws configure
Or set your credentials in the environment variables:
export AWS_ACCESS_KEY_ID='your_access_key_id' export AWS_SECRET_ACCESS_KEY='your_secret_access_key' export AWS_DEFAULT_REGION='your_aws_region'
Run the following command to apply the database migrations:
python manage.py migrateStart the Django development server:
python manage.py runserverThe application will be accessible at 'http://127.0.0.1:8000/'.
python manage.py runserver 0.0.0.0:8000The application will be available at 'Public IP address on the EC2 instance'
The frontend is a simple HTML page (index.html) that includes a form for the user to input text and a button to submit the text for sentiment analysis.
The backend is built using Django REST framework and includes an API endpoint that processes the text input from the frontend and sends it to AWS Comprehend for sentiment analysis.
The backend uses the AWS SDK for Python (Boto3) to interact with AWS Comprehend. The SentimentAnalysisView in api/views.py handles the sentiment analysis request.
This error is usually due to missing CSRF tokens in your POST requests. Ensure that your AJAX request includes the CSRF token as shown in the index.html file.
Make sure that your AWS credentials are correctly configured and have the necessary permissions to use AWS Comprehend.
This `README.md` file provides a comprehensive guide to setting up and running the Sentiment Analysis application, including the project structure, setup instructions, features, and troubleshooting tips. Adjust the repository URL and other specific details as needed for your project.