File size: 4,530 Bytes
aecbf43
7a00767
57cb63a
aecbf43
 
7a00767
 
aecbf43
 
7a00767
aecbf43
 
7a00767
aecbf43
7a00767
aecbf43
57cb63a
aecbf43
57cb63a
 
 
 
 
7a00767
 
aecbf43
57cb63a
aecbf43
7a00767
 
 
 
 
 
 
 
 
 
 
 
 
 
aecbf43
57cb63a
aecbf43
7a00767
 
57cb63a
 
 
aecbf43
7a00767
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57cb63a
aecbf43
57cb63a
aecbf43
57cb63a
aecbf43
57cb63a
aecbf43
57cb63a
 
aecbf43
57cb63a
aecbf43
57cb63a
 
aecbf43
57cb63a
aecbf43
57cb63a
aecbf43
57cb63a
aecbf43
57cb63a
aecbf43
7a00767
aecbf43
 
7a00767
 
 
 
 
 
 
 
 
 
57cb63a
aecbf43
 
7a00767
57cb63a
 
 
 
 
aecbf43
 
7a00767
 
 
 
 
 
 
 
 
 
 
 
57cb63a
aecbf43
57cb63a
 
7a00767
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
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:

```dart
// 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:
   ```bash
   pip install -r requirements.txt
   ```
3. Set your API key:
   ```bash
   export GOOGLE_AI_STUDIO_API_KEY=your_api_key_here
   ```
4. Run the application:
   ```bash
   uvicorn app:app --host 0.0.0.0 --port 7860 --reload
   ```

### Docker Development

```bash
# 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