This application leverages Go and Python to provide an advanced sentiment analysis API. It integrates a pre-trained machine learning model from Hugging Face to analyze text sentiment (Positive, Negative, or Neutral) and calculates confidence levels. Additionally, the app extracts significant keywords from the input text.
- ML-Based Sentiment Analysis: Utilizes a pre-trained
DistilBERT
model for accurate sentiment classification. - Confidence Scoring: Computes a confidence level for the sentiment classification.
- Keyword Extraction: Extracts meaningful keywords from the input text.
- Hybrid Architecture: Combines the speed and concurrency of Go with the ML capabilities of Python.
- Go Backend:
- Handles HTTP requests and response generation.
- Sends text input to the Python ML service.
- Extracts keywords using basic text processing.
- Python ML Service:
- Hosts the sentiment analysis model using the Hugging Face
transformers
library. - Processes text input and returns sentiment predictions to the Go backend.
- Hosts the sentiment analysis model using the Hugging Face
- Go: Version 1.18 or later.
- Python: Version 3.7 or later.
- Python Libraries:
flask
transformers
- Navigate to the
python_service
directory:cd python_service
- Install the required Python libraries:
pip install -r requirements.txt
- Start the ML service:
The service will run on port
python ml_service.py
5000
.
- Navigate to the
go_app
directory:cd ../go_app
- Run the Go application:
The server will start on port
go run main.go
8080
.
Analyzes the sentiment of the input text.
- URL:
http://localhost:8080/predict
- Method: POST
- Headers:
Content-Type: application/json
- Body:
{ "text": "I love coding with Go and Python!" }
- Example:
{ "text": "I love coding with Go and Python!", "sentiment": "POSITIVE", "confidence": 0.99, "keywords": ["love", "coding", "with", "Python"] }
- Python ML Service:
- Receives the input text.
- Processes the text using the
DistilBERT
sentiment analysis model. - Returns the sentiment and confidence levels.
- Go Backend:
- Sends the text to the Python ML service.
- Extracts significant keywords from the text.
- Combines results and returns them to the client.
Send a POST request:
curl -X POST -H "Content-Type: application/json" -d '{"text": "I love this advanced AI app!"}' http://localhost:8080/predict
- Create a new POST request.
- Set the URL to
http://localhost:8080/predict
. - Add a JSON body with the
text
field. - Send the request and view the response.
- Docker Integration:
- Containerize both the Go and Python services for easier deployment.
- Batch Processing:
- Allow analysis of multiple text inputs in a single request.
- Advanced NLP:
- Use libraries like
spaCy
for sophisticated keyword extraction.
- Use libraries like
- Multilingual Support:
- Add models for other languages to expand the app's capabilities.
This project is licensed under the MIT License.
Contributions are welcome! Feel free to open issues or submit pull requests to improve the application.