Skip to content

RamonRL/ml-api-sentiment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sentiment Analysis ML API

A production-ready sentiment analysis API built with FastAPI, scikit-learn, and Docker.


Overview

This API analyzes the sentiment of a given text (positive or negative) using a Machine Learning model.

The goal of this project is to demonstrate:

  • Building REST APIs with FastAPI
  • Integrating ML models into production systems
  • Writing clean, maintainable project structures
  • Testing and validation
  • Containerization with Docker

Tech Stack

  • Python
  • FastAPI
  • scikit-learn
  • Docker
  • Pytest

Project Structure

  • ml-api-sentiment/
    • app/

      • main.py # API endpoints
      • model/ # ML model
      • schemas/ # Request validation
      • services/ # Business logic
      • utils/ # Logging utilities
    • tests/ # Unit tests

    • Dockerfile

    • requirements.txt

    • README.md

Running the Project

1. Local setup

pip install -r requirements.txt

2. Run the API

2.1. Console

uvicorn app.main:app --reload

2.2. With Docker

Build the image

docker build -t sentiment-api .

Run the container

docker run -p 8010:8010 sentiment-api

2.2. Deployment (Render)

This project is deployed using Render. You can find a live demo in: https://sentiment-api-0zg1.onrender.com/docs

3. Test the API locally

Open:

API Endpoints

  • Health Check
GET /health

Response:

{
  "status": "healthy"
}
  • Predict Sentiment
POST /predict

Request:

{
  "text": "I love this product"
}

Response:

{
  "sentiment": "positive",
  "confidence": 0.87
}

Testing

Run tests with:

pytest

Features

  • REST API built with FastAPI
  • ML model integration
  • Input validation with Pydantic
  • Logging of requests and predictions
  • Error handling
  • Rate limiting
  • API versioning
  • Unit testing
  • Dockerized for deployment
  • Cloud deployment (Render)

Future improvements

  • Replace dummy model with a real trained dataset
  • Add authentication (API keys / JWT)
  • Monitoring (Prometheus / Grafana)
  • CI/CD pipeline

Author

Built as part of a Machine Learning / AI Engineering portfolio.

Motivation

This project demonstrates the ability to:

  • Bring ML models into production
  • Build scalable backend systems
  • Combine ML + backend engineering

About

A production-ready sentiment analysis API built with FastAPI, scikit-learn, Docker and Render.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors