Skip to content

SmartDrive-Platform/smartdrive-ai-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– SMARTDRIVE - AI Service

SMARTDRIVE AI Service
Version
Java Spring Boot Gemini AI
Intelligent Content Analysis and Metadata Generation Service

πŸ“‹ Overview

The AI Service is the intelligence layer of the SMARTDRIVE platform, providing advanced content analysis, metadata generation, and AI-powered insights for uploaded files. It integrates with Google Gemini AI, AWS Rekognition, and AWS Textract to deliver comprehensive file understanding.

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ File Storage    │───▢│   AI Service │───▢│ Google      β”‚
β”‚ Service         β”‚    β”‚              β”‚    β”‚ Gemini AI   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚ AWS         β”‚
                       β”‚ Rekognition β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚ AWS         β”‚
                       β”‚ Textract    β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features

πŸ–ΌοΈ Image Analysis

  • Object Detection using AWS Rekognition
  • Face Recognition and analysis
  • Text Extraction from images (OCR)
  • Image Labeling and classification
  • Content Moderation and safety checks

πŸ“„ Document Analysis

  • Text Extraction using AWS Textract
  • Document Structure analysis
  • Form Data extraction
  • Table Recognition and parsing
  • Handwriting Recognition

🧠 AI-Powered Insights

  • Content Summarization using Gemini AI
  • Keyword Extraction and tagging
  • Entity Recognition and classification
  • Sentiment Analysis
  • Topic Modeling

πŸ” Metadata Generation

  • Comprehensive Tags and categories
  • Content Descriptions and summaries
  • Search Optimization metadata
  • Accessibility information
  • Content Quality scoring

πŸ› οΈ Technology Stack

  • Framework: Spring Boot 3.2
  • Language: Java 17
  • AI Services: Google Gemini AI, AWS Rekognition, AWS Textract
  • Storage: AWS S3
  • Message Queue: AWS SQS
  • Monitoring: OpenTelemetry, Micrometer
  • Documentation: OpenAPI 3.0 (Swagger)

πŸš€ Quick Start

Prerequisites

  • Java 17+
  • Docker & Docker Compose
  • AWS Account with Rekognition and Textract access
  • Google Cloud Account with Gemini AI API access

Environment Variables

# AWS Configuration
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_REGION=us-east-1

# Google Gemini AI
GEMINI_API_KEY=your_gemini_api_key
GEMINI_BASE_URL=https://generativelanguage.googleapis.com/v1

# AWS Services
S3_BUCKET_NAME=smartdrive-uploads

# Service Configuration
SERVER_PORT=8082

Local Development

# Clone the repository
git clone <repository-url>
cd ai-service

# Build the project
./gradlew build

# Run with Docker Compose
docker compose up -d

# Or run locally
./gradlew bootRun

Docker Deployment

# Build Docker image
docker build -t smartdrive-ai-service .

# Run container
docker run -p 8082:8082 \
  -e AWS_ACCESS_KEY_ID=your_key \
  -e AWS_SECRET_ACCESS_KEY=your_secret \
  -e GEMINI_API_KEY=your_gemini_key \
  smartdrive-ai-service

πŸ“‘ API Endpoints

Generate Metadata

POST /api/v1/metadata/generate
Content-Type: application/json

{
  "contentId": "uuid",
  "s3Key": "uuid-document.pdf",
  "fileName": "document.pdf",
  "contentType": "application/pdf",
  "size": 1024000
}

# Response
{
  "contentId": "uuid",
  "tags": ["document", "pdf", "business"],
  "summary": "Business document containing quarterly reports...",
  "imageLabels": ["text", "document", "paper"],
  "imageObjects": ["person", "chart", "graph"],
  "imageText": ["Q1 2024", "Revenue", "$1.2M"],
  "extractedText": "Quarterly Report Q1 2024...",
  "processingStatus": "COMPLETED"
}

Process Image

POST /api/v1/images/analyze
Content-Type: multipart/form-data

# Response
{
  "labels": ["person", "office", "business"],
  "objects": ["person", "desk", "computer"],
  "faces": ["adult", "male", "smiling"],
  "text": ["Meeting", "Schedule", "9:00 AM"]
}

Process Document

POST /api/v1/documents/extract
Content-Type: multipart/form-data

# Response
{
  "text": "Extracted text content...",
  "tables": [{"headers": ["Name", "Value"], "rows": [...]}],
  "forms": [{"key": "Date", "value": "2024-01-01"}]
}

πŸ”§ Configuration

Application Properties

server:
  port: 8082

spring:
  application:
    name: ai-service

app:
  s3:
    bucket-name: ${S3_BUCKET_NAME:smartdrive-uploads}
  gemini:
    api-key: ${GEMINI_API_KEY}
    base-url: ${GEMINI_BASE_URL:https://generativelanguage.googleapis.com/v1}
  ai:
    max-image-size: 5MB
    supported-image-types:
      - image/jpeg
      - image/png
      - image/gif
    supported-document-types:
      - application/pdf
      - image/tiff
      - image/png

AI Service Configuration

@Configuration
public class AiConfig {
    @Bean
    public RekognitionClient rekognitionClient() {
        return RekognitionClient.builder().build();
    }
    
    @Bean
    public TextractClient textractClient() {
        return TextractClient.builder().build();
    }
}

πŸ“Š Monitoring

Health Checks

GET /actuator/health
GET /actuator/health/aws-rekognition
GET /actuator/health/aws-textract
GET /actuator/health/gemini-ai

Metrics

  • Processing Success Rate: smartdrive.ai.processing.success.rate
  • Processing Time: smartdrive.ai.processing.time
  • AI Service Latency: smartdrive.ai.service.latency
  • Error Rate: smartdrive.ai.error.rate

Logging

logging:
  level:
    com.smartdrive.aiservice: INFO
    software.amazon.awssdk: INFO
  pattern:
    console: "%d{HH:mm:ss.SSS} [%X{traceId:-}] %-5level %logger{20} - %msg%n"

πŸ”’ Security

API Security

  • Rate Limiting for AI API calls
  • Input Validation and sanitization
  • Content Filtering and moderation
  • Privacy Protection for sensitive content

Data Protection

  • Secure API Keys management
  • Content Encryption in transit
  • Audit Logging for all AI operations
  • GDPR Compliance for data processing

πŸ§ͺ Testing

Unit Tests

./gradlew test

Integration Tests

./gradlew integrationTest

AI Service Testing

# Test image analysis
curl -X POST http://localhost:8082/api/v1/images/analyze \
  -F "[email protected]"

# Test document extraction
curl -X POST http://localhost:8082/api/v1/documents/extract \
  -F "[email protected]"

πŸš€ Deployment

Docker Compose

version: '3.8'
services:
  ai-service:
    build: .
    ports:
      - "8082:8082"
    environment:
      - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
      - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
      - GEMINI_API_KEY=${GEMINI_API_KEY}
    depends_on:
      - elasticsearch
      - redis

Kubernetes

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ai-service
spec:
  replicas: 3
  selector:
    matchLabels:
      app: ai-service
  template:
    metadata:
      labels:
        app: ai-service
    spec:
      containers:
      - name: ai-service
        image: smartdrive/ai-service:latest
        ports:
        - containerPort: 8082
        env:
        - name: GEMINI_API_KEY
          valueFrom:
            secretKeyRef:
              name: ai-credentials
              key: gemini-api-key

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

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

πŸ†˜ Support


Built with ❀️ by the SMARTDRIVE Team
🌐 Website β€’ πŸ“š Docs β€’ οΏ½οΏ½ GitHub

About

SmartDrive AI Service - AI-powered metadata generation and analysis for files

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published