Spaces:
Sleeping
Sleeping
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
- Visit the main page
- Upload Image: Click on the upload area and select your lab report image
- Analyze: Click the "Analyze Report" button
- 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
- Clone the repository
- Install dependencies:
pip install -r requirements.txt - Set your API key:
export GOOGLE_AI_STUDIO_API_KEY=your_api_key_here - 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