YoussefSalem582/Emosense-Backend

0

stars

31

commits

Python

primary language

Jul 3, 2026

updated

emosense-backend.vercel.app

README

EmoSense Backend API

A comprehensive FastAPI backend for emotion analysis providing text, audio, and video emotion detection with global deployment capability.

πŸš€ Current Status: Production Ready

βœ… Railway Deployment Ready - Optimized for global free deployment
βœ… Localhost Testing Ready - Flutter integration testing available
βœ… Clean Codebase - Unused files removed, focused structure
βœ… ML Models Ready - Real emotion models + lightweight alternatives

🎯 Quick Start

# Use the ready-to-deploy package
cd deploy_railway/
# Follow instructions in deploy_railway/README.md

🏠 Test Locally with Flutter

# Start localhost server for Flutter testing
python localhost_test_server.py
# Server runs on http://localhost:8000

πŸ”§ Development Server

# Full development server
python production_server.py

οΏ½ Project Structure (Cleaned)

emosense_backend/
β”œβ”€β”€ πŸš‚ deploy_railway/          # Production deployment (Railway)
β”‚   β”œβ”€β”€ Dockerfile             # Optimized container
β”‚   β”œβ”€β”€ requirements_railway.txt
β”‚   β”œβ”€β”€ production_server_railway.py
β”‚   β”œβ”€β”€ api/emotion_models_railway.py
β”‚   └── README.md              # Deployment guide
β”œβ”€β”€ πŸ”§ api/                     # Core emotion analysis
β”‚   β”œβ”€β”€ emotion_models.py      # Full emotion models
β”‚   β”œβ”€β”€ emotion_models_lite.py # Lightweight models
β”‚   └── index.py               # API endpoints
β”œβ”€β”€ πŸ“± app/                     # FastAPI application
β”‚   β”œβ”€β”€ main.py                # Application entry
β”‚   β”œβ”€β”€ api/                   # API routes
β”‚   β”œβ”€β”€ models/                # Database models  
β”‚   └── services/              # Business logic
β”œβ”€β”€ πŸ§ͺ tests/                   # Test suite
β”œβ”€β”€ πŸ€– real_models/             # Trained ML models
β”œβ”€β”€ 🏠 localhost_test_server.py # Flutter testing server
β”œβ”€β”€ πŸš€ production_server.py     # Development server
└── πŸ“‹ requirements.txt         # Dependencies

β”‚ β”œβ”€β”€ core/ # Core functionality β”‚ β”‚ β”œβ”€β”€ init.py β”‚ β”‚ β”œβ”€β”€ security.py # Security utilities β”‚ β”‚ └── exceptions.py # Custom exceptions β”‚ β”œβ”€β”€ models/ # Database models β”‚ β”‚ β”œβ”€β”€ init.py β”‚ β”‚ β”œβ”€β”€ user.py # User model β”‚ β”‚ └── emotion.py # Emotion analysis models β”‚ β”œβ”€β”€ schemas/ # Pydantic schemas β”‚ β”‚ β”œβ”€β”€ init.py β”‚ β”‚ β”œβ”€β”€ user.py # User schemas β”‚ β”‚ └── emotion.py # Emotion analysis schemas β”‚ β”œβ”€β”€ services/ # Business logic β”‚ β”‚ β”œβ”€β”€ init.py β”‚ β”‚ β”œβ”€β”€ health.py # Health check service β”‚ β”‚ └── emotion/ # Emotion analysis services β”‚ └── utils/ # Utility functions β”œβ”€β”€ tests/ # Test files β”œβ”€β”€ .github/ # GitHub configuration β”‚ └── copilot-instructions.md # Copilot instructions β”œβ”€β”€ requirements.txt # Python dependencies β”œβ”€β”€ docker-compose.yml # Docker setup β”œβ”€β”€ Dockerfile # Docker image β”œβ”€β”€ .env.example # Environment variables template └── README.md # This file


## πŸš€ Quick Start

### Prerequisites

- Python 3.9+
- PostgreSQL 12+
- Redis 6+
- FFmpeg (for audio/video processing)

### Installation

1. **Clone the repository and set up virtual environment:**
   ```bash
   python -m venv venv
   source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:

    pip install -r requirements.txt
    
  2. Set up environment variables:

    cp .env.example .env
    # Edit .env with your configuration
    
  3. Set up database:

    # Create PostgreSQL database
    createdb emosense_db
    
    # Run migrations
    alembic upgrade head
    
  4. Run the application:

    uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
    
# Start all services
docker-compose up -d

# View logs
docker-compose logs -f app

# Stop services
docker-compose down

πŸ“š API Documentation

Once the server is running, visit:

πŸ”— API Endpoints

Authentication

  • POST /api/v1/auth/register - User registration
  • POST /api/v1/auth/login - User login
  • POST /api/v1/auth/refresh - Refresh access token
  • POST /api/v1/auth/logout - User logout

Emotion Analysis

  • POST /api/v1/emotion/text - Analyze text emotions
  • POST /api/v1/emotion/video - Analyze video emotions
  • POST /api/v1/emotion/audio - Analyze audio emotions
  • POST /api/v1/emotion/batch - Batch analysis
  • GET /api/v1/emotion/{analysis_id} - Get analysis results
  • GET /api/v1/emotion/ - List user analyses

Analytics

  • GET /api/v1/analytics/dashboard - Analytics dashboard data
  • GET /api/v1/analytics/reports - Generate reports
  • GET /api/v1/analytics/stats - Usage statistics

System

  • GET /health - Health check
  • GET /metrics - System metrics
  • GET /api/v1/system/info - System information

βš™οΈ Configuration

Key environment variables (see .env.example for complete list):

# Application
ENVIRONMENT=development
DEBUG=true
SECRET_KEY=your-super-secret-key

# Database
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/emosense_db

# Redis
REDIS_URL=redis://localhost:6379/0

# Security
ACCESS_TOKEN_EXPIRE_MINUTES=30
REFRESH_TOKEN_EXPIRE_DAYS=7

πŸ§ͺ Testing

# Install test dependencies
pip install pytest pytest-asyncio pytest-mock

# Run tests
pytest tests/

# Run with coverage
pytest --cov=app tests/

πŸš€ Deployment

Production Deployment

  1. Environment Setup:

    # Set production environment variables
    export ENVIRONMENT=production
    export DEBUG=false
    export SECRET_KEY=your-secure-production-key
    
  2. Database Migration:

    alembic upgrade head
    
  3. Start with Gunicorn:

    gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker
    

Docker Production

# Build production image
docker build -t emosense-backend .

# Run with docker-compose (production profile)
docker-compose --profile production up -d

πŸ“Š Monitoring

  • Health Check: GET /health
  • Metrics: GET /metrics (Prometheus format)
  • Flower (Celery monitoring): http://localhost:5555

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

πŸ“ Development Guidelines

  • Follow PEP 8 style guidelines
  • Use type hints throughout the codebase
  • Write comprehensive tests
  • Document all functions and classes
  • Use async/await for I/O operations
  • Implement proper error handling

πŸ”’ Security

  • JWT-based authentication
  • Password hashing with bcrypt
  • Input validation and sanitization
  • Rate limiting
  • CORS configuration
  • Secure file upload handling

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™‹β€β™‚οΈ Support

For support, please contact the development team or create an issue in the repository.


Built with ❀️ using FastAPI and modern Python technologies.

Contributors

YoussefSalem582

31 commits

YoussefSalem582/Emosense-Backend

0

stars

31

commits

Python

primary language

Jul 3, 2026

updated

emosense-backend.vercel.app

README

EmoSense Backend API

A comprehensive FastAPI backend for emotion analysis providing text, audio, and video emotion detection with global deployment capability.

πŸš€ Current Status: Production Ready

βœ… Railway Deployment Ready - Optimized for global free deployment
βœ… Localhost Testing Ready - Flutter integration testing available
βœ… Clean Codebase - Unused files removed, focused structure
βœ… ML Models Ready - Real emotion models + lightweight alternatives

🎯 Quick Start

# Use the ready-to-deploy package
cd deploy_railway/
# Follow instructions in deploy_railway/README.md

🏠 Test Locally with Flutter

# Start localhost server for Flutter testing
python localhost_test_server.py
# Server runs on http://localhost:8000

πŸ”§ Development Server

# Full development server
python production_server.py

οΏ½ Project Structure (Cleaned)

emosense_backend/
β”œβ”€β”€ πŸš‚ deploy_railway/          # Production deployment (Railway)
β”‚   β”œβ”€β”€ Dockerfile             # Optimized container
β”‚   β”œβ”€β”€ requirements_railway.txt
β”‚   β”œβ”€β”€ production_server_railway.py
β”‚   β”œβ”€β”€ api/emotion_models_railway.py
β”‚   └── README.md              # Deployment guide
β”œβ”€β”€ πŸ”§ api/                     # Core emotion analysis
β”‚   β”œβ”€β”€ emotion_models.py      # Full emotion models
β”‚   β”œβ”€β”€ emotion_models_lite.py # Lightweight models
β”‚   └── index.py               # API endpoints
β”œβ”€β”€ πŸ“± app/                     # FastAPI application
β”‚   β”œβ”€β”€ main.py                # Application entry
β”‚   β”œβ”€β”€ api/                   # API routes
β”‚   β”œβ”€β”€ models/                # Database models  
β”‚   └── services/              # Business logic
β”œβ”€β”€ πŸ§ͺ tests/                   # Test suite
β”œβ”€β”€ πŸ€– real_models/             # Trained ML models
β”œβ”€β”€ 🏠 localhost_test_server.py # Flutter testing server
β”œβ”€β”€ πŸš€ production_server.py     # Development server
└── πŸ“‹ requirements.txt         # Dependencies

β”‚ β”œβ”€β”€ core/ # Core functionality β”‚ β”‚ β”œβ”€β”€ init.py β”‚ β”‚ β”œβ”€β”€ security.py # Security utilities β”‚ β”‚ └── exceptions.py # Custom exceptions β”‚ β”œβ”€β”€ models/ # Database models β”‚ β”‚ β”œβ”€β”€ init.py β”‚ β”‚ β”œβ”€β”€ user.py # User model β”‚ β”‚ └── emotion.py # Emotion analysis models β”‚ β”œβ”€β”€ schemas/ # Pydantic schemas β”‚ β”‚ β”œβ”€β”€ init.py β”‚ β”‚ β”œβ”€β”€ user.py # User schemas β”‚ β”‚ └── emotion.py # Emotion analysis schemas β”‚ β”œβ”€β”€ services/ # Business logic β”‚ β”‚ β”œβ”€β”€ init.py β”‚ β”‚ β”œβ”€β”€ health.py # Health check service β”‚ β”‚ └── emotion/ # Emotion analysis services β”‚ └── utils/ # Utility functions β”œβ”€β”€ tests/ # Test files β”œβ”€β”€ .github/ # GitHub configuration β”‚ └── copilot-instructions.md # Copilot instructions β”œβ”€β”€ requirements.txt # Python dependencies β”œβ”€β”€ docker-compose.yml # Docker setup β”œβ”€β”€ Dockerfile # Docker image β”œβ”€β”€ .env.example # Environment variables template └── README.md # This file


## πŸš€ Quick Start

### Prerequisites

- Python 3.9+
- PostgreSQL 12+
- Redis 6+
- FFmpeg (for audio/video processing)

### Installation

1. **Clone the repository and set up virtual environment:**
   ```bash
   python -m venv venv
   source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:

    pip install -r requirements.txt
    
  2. Set up environment variables:

    cp .env.example .env
    # Edit .env with your configuration
    
  3. Set up database:

    # Create PostgreSQL database
    createdb emosense_db
    
    # Run migrations
    alembic upgrade head
    
  4. Run the application:

    uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
    
# Start all services
docker-compose up -d

# View logs
docker-compose logs -f app

# Stop services
docker-compose down

πŸ“š API Documentation

Once the server is running, visit:

πŸ”— API Endpoints

Authentication

  • POST /api/v1/auth/register - User registration
  • POST /api/v1/auth/login - User login
  • POST /api/v1/auth/refresh - Refresh access token
  • POST /api/v1/auth/logout - User logout

Emotion Analysis

  • POST /api/v1/emotion/text - Analyze text emotions
  • POST /api/v1/emotion/video - Analyze video emotions
  • POST /api/v1/emotion/audio - Analyze audio emotions
  • POST /api/v1/emotion/batch - Batch analysis
  • GET /api/v1/emotion/{analysis_id} - Get analysis results
  • GET /api/v1/emotion/ - List user analyses

Analytics

  • GET /api/v1/analytics/dashboard - Analytics dashboard data
  • GET /api/v1/analytics/reports - Generate reports
  • GET /api/v1/analytics/stats - Usage statistics

System

  • GET /health - Health check
  • GET /metrics - System metrics
  • GET /api/v1/system/info - System information

βš™οΈ Configuration

Key environment variables (see .env.example for complete list):

# Application
ENVIRONMENT=development
DEBUG=true
SECRET_KEY=your-super-secret-key

# Database
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/emosense_db

# Redis
REDIS_URL=redis://localhost:6379/0

# Security
ACCESS_TOKEN_EXPIRE_MINUTES=30
REFRESH_TOKEN_EXPIRE_DAYS=7

πŸ§ͺ Testing

# Install test dependencies
pip install pytest pytest-asyncio pytest-mock

# Run tests
pytest tests/

# Run with coverage
pytest --cov=app tests/

πŸš€ Deployment

Production Deployment

  1. Environment Setup:

    # Set production environment variables
    export ENVIRONMENT=production
    export DEBUG=false
    export SECRET_KEY=your-secure-production-key
    
  2. Database Migration:

    alembic upgrade head
    
  3. Start with Gunicorn:

    gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker
    

Docker Production

# Build production image
docker build -t emosense-backend .

# Run with docker-compose (production profile)
docker-compose --profile production up -d

πŸ“Š Monitoring

  • Health Check: GET /health
  • Metrics: GET /metrics (Prometheus format)
  • Flower (Celery monitoring): http://localhost:5555

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

πŸ“ Development Guidelines

  • Follow PEP 8 style guidelines
  • Use type hints throughout the codebase
  • Write comprehensive tests
  • Document all functions and classes
  • Use async/await for I/O operations
  • Implement proper error handling

πŸ”’ Security

  • JWT-based authentication
  • Password hashing with bcrypt
  • Input validation and sanitization
  • Rate limiting
  • CORS configuration
  • Secure file upload handling

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™‹β€β™‚οΈ Support

For support, please contact the development team or create an issue in the repository.


Built with ❀️ using FastAPI and modern Python technologies.

Contributors

YoussefSalem582

31 commits

Languages

Python

99.5%