This project is a Sentiment Analysis API that takes user input text and predicts its sentiment using Hugging Face Hub. It is built with FastAPI for the backend and deployed on Koyeb.
- FastAPI – Backend framework
- Hugging Face Hub – Sentiment analysis model
- Koyeb – Deployment platform
git clone https://github.com/your-username/sentiment-analysis-api.git
cd sentiment-analysis-apipython -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtCreate a .env file and add your Hugging Face API Token:
HUGGINGFACEHUB_API_TOKEN=your_huggingface_api_token_here
uvicorn main:app --reloadThe API will be available at http://127.0.0.1:8000.
POST /analyze_sentiment/
{
"text": "I love this product!"
}{
"text": "I love this product!",
"sentiment": "5 stars"
}A simple HTML frontend is provided in index.html, which sends a request to the API and displays the sentiment result.
The API is deployed on Koyeb, a serverless platform for easy deployment. Steps to deploy:
- Create a new service on Koyeb.
- Connect your GitHub repository.
- Set environment variables in Koyeb.
- Deploy and get the API URL.
🚀 Enjoy building with FastAPI and Hugging Face!
