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.
- 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
- Python
- FastAPI
- Pydantic
- Uvicorn
- Google Gemini Vision API
- Pillow (PIL)
- API Key Authentication
- Docker
- Pytest
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
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": []
}POST /analyze-base64
Supports
- Base64 Images
- Data URI
- Local File Path
POST /admin/generate-key
Creates API keys for authenticated users.
- Receive uploaded image
- Validate file size
- Validate image format
- Normalize image
- Resize if required
- Send image to Gemini API
- Receive AI response
- Normalize output
- Return structured JSON
General image understanding.
Identify objects and categories.
Extract text and information.
Specialized prompt that extracts
- Product Name
- Jewelry Type
- Metal
- Stone
- Color
- SEO Title
- SEO Description
- Marketing Text
- Confidence Score
git clone https://github.com/dipayan3203/Image-Analyzer.gitpip install -r requirements.txtCreate a .env
GEMINI_API_KEY=YOUR_KEY
GEMINI_MODEL=gemini-2.5-flash
uvicorn app.main:app --reloadSwagger UI
http://localhost:8000/docs
pytest
- Batch image analysis
- Async background processing
- Rate limiting
- Response caching
- Database persistence
- User authentication (JWT)
- Image history
- Multi-model AI support
app/
│
├── main.py
├── gemini_client.py
├── middleware.py
├── normalizer.py
├── preprocessor.py
├── schemas.py
├── database.py
│
├── static/
│
tests/
│
Dockerfile
requirements.txt
- FastAPI REST API development
- Google Gemini Vision API integration
- Image preprocessing using Pillow
- API authentication
- Response normalization
- Dockerized deployment
- Error handling
- AI application development
Dipayan Mahato
Python Backend Developer