This project is a language detection service built with FastAPI, integrated with Google Cloud Translation API, and backed by a PostgreSQL database. It demonstrates best practices in developing and deploying web applications using FastAPI, Google Cloud services, and relational database management systems. It saves the words and the corresponding language they were written in, in the Database. Additionally, it features a sentiment analysis component, utilizing a Go-based sentiment analysis tool to evaluate the sentiment of the input text.
- FastAPI Framework: Utilizes FastAPI for building high-performance APIs with Python 3.7+, leveraging standard Python type hints.
- Asynchronous Handling: Capable of handling asynchronous requests, enhancing performance in demanding scenarios.
- Google Cloud Translation API Integration: Seamlessly integrates with Google Cloud Translation API for accurate language detection.
- PostgreSQL Database Integration: Incorporates a PostgreSQL database to store and manage detected language data.
- Automatic API Documentation: Features automatically generated interactive API documentation using Swagger UI.
- Sentiment Analysis: Offers sentiment analysis through a Go-based tool, providing insights into the emotional tone behind texts.
- Python 3.7+
- FastAPI
- Uvicorn (ASGI server)
- Google Cloud Account with Translation API access
- PostgreSQL database
- Go 1.21.6 (for sentiment analysis component)
Clone the repository:
git clone [https://github.com/your-username/your-repository-name.git](https://github.com/joaovasco01/Unbabel_Technologies.git)
Navigate to the project directory:
cd Unbabel_Technologies
Create a virtual environment:
python -m venv venv
source venv/bin/activate # Unix/macOS
venv\Scripts\activate # Windows
Install Python dependencies:
pip install -r requirements.txt
Ensure Go is installed and set up the Go environment for the sentiment analysis tool:
- Install Go from the official website.
- Navigate to the
sentiment_analysis
directory and rungo build
to compile the Go program.
- Set up the Google Cloud service account and download the JSON key file.
- Place the key file in a secure location and update
GOOGLE_CREDENTIALS
inmain.py
with its path. - Ensure PostgreSQL is installed and running. Update
SQLALCHEMY_DATABASE_URL
inmain.py
with your database credentials. - For sentiment analysis, ensure the compiled Go executable is accessible to
main.py
, adjusting the path in theanalyze_sentiment_with_go
function as necessary.
Start the FastAPI server:
uvicorn main:app --reload
The service will be available at http://127.0.0.1:8000
.
Access the interactive API documentation at http://127.0.0.1:8000/docs
.
To detect the language of a text, send a POST request to the /detect-language/
endpoint with a JSON payload containing the text:
curl -X 'POST' \
'http://127.0.0.1:8000/detect-language/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"content": "Hello, world"}'
To analyze the sentiment of a text, send a POST request to the /analyze-sentiment/
endpoint with a JSON payload containing the text:
curl -X 'POST' \
'http://127.0.0.1:8000/analyze-sentiment/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"content": "I love sunny days!"}'
The detected language and sentiment analysis results will be returned in the response and stored in the PostgreSQL database for record-keeping and further analysis.
![Screenshot 2024-01-26 at 1 38 38 AM](https://private-user-images.githubusercontent.com/61276111/299862187-4bd2f772-14b1-4372-b61d-a372b278834b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjExMDc0NzEsIm5iZiI6MTcyMTEwNzE3MSwicGF0aCI6Ii82MTI3NjExMS8yOTk4NjIxODctNGJkMmY3NzItMTRiMS00MzcyLWI2MWQtYTM3MmIyNzg4MzRiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE2VDA1MTkzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ1ZWJjZDRlOTUwMWUxYjFmY2Q3ZDA5OTI5NGE3ZGUxZTQ3OGI0OTYwMTdhNGQ1MTlmOTk2ZmMzNjY0NmNjNmEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.TP5Oj5SYd2hFtahi-MxdTzsnQZTbvILxOkM0KFN0Q78)