Lab_analyzer / README.md
Tantawi65
Converted to pure FastAPI with beautiful web interface - Flutter compatible
7a00767
metadata
title: Lab Report Analysis API
emoji: πŸ₯
colorFrom: blue
colorTo: green
sdk: docker
app_port: 7860
pinned: false
license: apache-2.0
short_description: AI-powered lab report analysis API using Google AI Studio

πŸ₯ Lab Report Analysis API

A powerful FastAPI-based web service for analyzing medical lab reports using Google AI Studio's Gemini model. Provides both a beautiful web interface and REST API endpoints for programmatic access.

✨ Features

  • πŸ“Έ Image Analysis: Upload lab report images in various formats (JPG, PNG, TIFF, etc.)
  • πŸ€– AI-Powered: Uses Google's Gemini 2.0 Flash model for accurate analysis
  • πŸ“Š Structured Output: Provides organized summary, key findings, and interpretations
  • ⚑ Fast Processing: Quick analysis with real-time results
  • πŸ”’ Secure: Images are processed securely and not stored
  • 🌐 Web Interface: Beautiful HTML interface for manual testing
  • πŸ“± Flutter Compatible: Full REST API support for mobile apps

πŸš€ How to Use

Web Interface

  1. Visit the main page
  2. Upload Image: Click on the upload area and select your lab report image
  3. Analyze: Click the "Analyze Report" button
  4. Review Results: Get structured analysis with summary, key findings, and interpretations

API Endpoints

  • POST /analyze - Upload file analysis
  • POST /analyze-base64 - Base64 image analysis
  • POST /api/analyze-lab - Flutter-friendly file upload
  • POST /api/analyze-lab-base64 - Flutter-friendly base64 analysis
  • GET /health - Health check endpoint
  • GET /docs - Interactive API documentation
  • GET /redoc - ReDoc documentation

πŸ› οΈ Technology Stack

  • Backend: FastAPI for high-performance API
  • Frontend: Custom HTML/CSS/JavaScript interface
  • AI Model: Google AI Studio (Gemini 2.0 Flash)
  • Image Processing: PIL for image handling
  • Deployment: Docker containerization for Hugging Face Spaces

πŸ“± Flutter Integration

Perfect for Flutter apps! All endpoints return consistent JSON responses:

// File upload
POST /api/analyze-lab
Content-Type: multipart/form-data

// Base64 upload  
POST /api/analyze-lab-base64
Content-Type: application/json
{
  "image": "base64_encoded_image_string"
}

// Response format
{
  "success": true,
  "filename": "lab_report.jpg",
  "analysis": {
    "error": false,
    "summary": "Analysis summary",
    "key_findings": ["Finding 1", "Finding 2"],
    "interpretation": "Medical interpretation",
    "note": "Disclaimer about medical advice",
    "raw_response": "Full AI response"
  }
}

⚠️ Important Disclaimer

This tool is for educational and informational purposes only. It should not be used as a substitute for professional medical advice, diagnosis, or treatment. Always consult with qualified healthcare professionals for medical concerns.

πŸ—οΈ Local Development

Prerequisites

  • Python 3.11+
  • Google AI Studio API key

Installation

  1. Clone the repository
  2. Install dependencies:
    pip install -r requirements.txt
    
  3. Set your API key:
    export GOOGLE_AI_STUDIO_API_KEY=your_api_key_here
    
  4. Run the application:
    uvicorn app:app --host 0.0.0.0 --port 7860 --reload
    

Docker Development

# Build the image
docker build -t lab-analysis-api .

# Run the container
docker run -p 7860:7860 -e GOOGLE_AI_STUDIO_API_KEY=your_key lab-analysis-api

πŸ“ Project Structure

β”œβ”€β”€ app.py                 # Main FastAPI application with web interface
β”œβ”€β”€ lab_analyzer.py       # Core analysis logic
β”œβ”€β”€ models.py            # Data models
β”œβ”€β”€ requirements.txt     # Python dependencies
β”œβ”€β”€ Dockerfile          # Container configuration
└── README.md           # Documentation

🎯 Endpoints Overview

Method Endpoint Description Use Case
GET / Web interface Manual testing
POST /analyze File upload analysis General API usage
POST /analyze-base64 Base64 analysis Web applications
POST /api/analyze-lab Flutter file upload Mobile apps
POST /api/analyze-lab-base64 Flutter base64 Mobile apps
GET /health Health check Monitoring
GET /docs OpenAPI docs API reference

πŸ™ Acknowledgments

  • Google AI Studio for providing the Gemini API
  • Hugging Face for Spaces hosting
  • FastAPI for the excellent web framework