Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gemini Image Analyzer

An AI-powered image analysis service built with FastAPI and Google Gemini Vision API.

The application accepts image uploads or Base64-encoded images, validates and preprocesses them, sends them to the Gemini Vision model for analysis, and returns a clean, structured JSON response suitable for frontend applications and downstream systems.


Features

  • AI-powered image analysis using Google Gemini Vision API
  • Upload images (JPEG, PNG, GIF, BMP)
  • Analyze images from Base64 strings
  • Multiple analysis modes
    • General Analysis
    • Image Classification
    • Text Extraction
    • Jewelry Product Analysis
  • Image validation and preprocessing
  • Automatic image resizing
  • Structured JSON responses
  • API Key authentication
  • Docker support
  • Unit tests
  • Interactive API documentation using Swagger

Tech Stack

Backend

  • Python
  • FastAPI
  • Pydantic
  • Uvicorn

AI

  • Google Gemini Vision API

Image Processing

  • Pillow (PIL)

Security

  • API Key Authentication

Deployment

  • Docker

Testing

  • Pytest

Project Architecture

                Client
                   │
        Upload Image / Base64
                   │
                   ▼
          FastAPI REST API
                   │
         Request Validation
                   │
                   ▼
      Image Preprocessing Layer
      --------------------------
      • Validate image format
      • Validate size
      • Resize large images
                   │
                   ▼
         Gemini Client Layer
                   │
        Google Gemini Vision API
                   │
                   ▼
           AI Response
                   │
                   ▼
        Response Normalizer
                   │
                   ▼
        Structured JSON Output

API Endpoints

Analyze Uploaded Image

POST /analyze

Consumes:

  • Multipart Form Data
  • UploadFile

Parameters

Parameter Type Required
file UploadFile Yes
analysis_type Form No

Example

POST /analyze

Returns

{
  "status": "success",
  "analysis": {
    "description": "...",
    "labels": [],
    "confidence": 0.98
  },
  "errors": []
}

Analyze Base64 Image

POST /analyze-base64

Supports

  • Base64 Images
  • Data URI
  • Local File Path

Generate API Key

POST /admin/generate-key

Creates API keys for authenticated users.


Image Processing Pipeline

  1. Receive uploaded image
  2. Validate file size
  3. Validate image format
  4. Normalize image
  5. Resize if required
  6. Send image to Gemini API
  7. Receive AI response
  8. Normalize output
  9. Return structured JSON

Supported Analysis Types

General

General image understanding.

Classification

Identify objects and categories.

Extraction

Extract text and information.

Jewelry

Specialized prompt that extracts

  • Product Name
  • Jewelry Type
  • Metal
  • Stone
  • Color
  • SEO Title
  • SEO Description
  • Marketing Text
  • Confidence Score

Running Locally

Clone

git clone https://github.com/dipayan3203/Image-Analyzer.git

Install

pip install -r requirements.txt

Environment Variables

Create a .env

GEMINI_API_KEY=YOUR_KEY
GEMINI_MODEL=gemini-2.5-flash

Run

uvicorn app.main:app --reload

API Documentation

Swagger UI

http://localhost:8000/docs

Testing

pytest

Future Improvements

  • Batch image analysis
  • Async background processing
  • Rate limiting
  • Response caching
  • Database persistence
  • User authentication (JWT)
  • Image history
  • Multi-model AI support

Folder Structure

app/
│
├── main.py
├── gemini_client.py
├── middleware.py
├── normalizer.py
├── preprocessor.py
├── schemas.py
├── database.py
│
├── static/
│
tests/
│
Dockerfile
requirements.txt

Key Learnings

  • FastAPI REST API development
  • Google Gemini Vision API integration
  • Image preprocessing using Pillow
  • API authentication
  • Response normalization
  • Dockerized deployment
  • Error handling
  • AI application development

Author

Dipayan Mahato

Python Backend Developer

About

AI image analysis app powered by Google Gemini API.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages