Tantawi commited on
Commit
aecbf43
Β·
verified Β·
1 Parent(s): 3d47039

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +272 -261
README.md CHANGED
@@ -1,261 +1,272 @@
1
- # Lab Report Analysis API
2
-
3
- A FastAPI-based web service for analyzing lab report images using AI. This service accepts lab report images and provides structured medical analysis with key findings, interpretations, and health insights.
4
-
5
- ## Features
6
-
7
- - πŸ–ΌοΈ Image upload support (JPG, PNG, BMP, TIFF, WEBP)
8
- - πŸ” AI-powered lab report analysis
9
- - πŸ“Š Structured response with summary, key findings, and interpretation
10
- - 🌐 RESTful API with automatic documentation
11
- - πŸ§ͺ Built-in test client and web interface
12
- - ⚑ Async processing for better performance
13
-
14
- ## Project Structure
15
-
16
- ```
17
- Lab_analysis/
18
- β”œβ”€β”€ main.py # FastAPI application
19
- β”œβ”€β”€ lab_analyzer.py # Core analysis logic
20
- β”œβ”€β”€ models.py # Pydantic models
21
- β”œβ”€β”€ test_client.py # API test client
22
- β”œβ”€β”€ index.html # Web interface
23
- β”œβ”€β”€ requirements.txt # Dependencies
24
- β”œβ”€β”€ Lab_report_analysis.py # Original script
25
- └── README.md # This file
26
- ```
27
-
28
- ## Installation
29
-
30
- 1. **Clone or navigate to the project directory:**
31
-
32
- ```bash
33
- cd "e:\E-JUST Assignments\Projects\HealthCare\Lab_analysis"
34
- ```
35
-
36
- 2. **Create a virtual environment (recommended):**
37
-
38
- ```bash
39
- python -m venv venv
40
- venv\Scripts\activate # On Windows
41
- ```
42
-
43
- 3. **Install dependencies:**
44
- ```bash
45
- pip install -r requirements.txt
46
- ```
47
-
48
- ## Running the API
49
-
50
- ### Method 1: Using Python directly
51
-
52
- ```bash
53
- python main.py
54
- ```
55
-
56
- ### Method 2: Using Uvicorn
57
-
58
- ```bash
59
- uvicorn main:app --host 0.0.0.0 --port 8000 --reload
60
- ```
61
-
62
- The API will be available at:
63
-
64
- - **API Endpoints**: http://localhost:8000
65
- - **Interactive Docs**: http://localhost:8000/docs
66
- - **ReDoc**: http://localhost:8000/redoc
67
-
68
- ## API Endpoints
69
-
70
- ### Health Check
71
-
72
- - **GET** `/health`
73
- - Returns service status
74
-
75
- ### Analyze Lab Report (File Upload)
76
-
77
- - **POST** `/analyze`
78
- - Upload an image file for analysis
79
- - Accepts: `multipart/form-data` with `file` field
80
-
81
- ### Analyze Lab Report (Base64)
82
-
83
- - **POST** `/analyze-base64`
84
- - Send base64 encoded image for analysis
85
- - Accepts: JSON with `image` field containing base64 string
86
-
87
- ## Usage Examples
88
-
89
- ### Using cURL
90
-
91
- 1. **Health check:**
92
-
93
- ```bash
94
- curl http://localhost:8000/health
95
- ```
96
-
97
- 2. **Analyze image file:**
98
-
99
- ```bash
100
- curl -X POST "http://localhost:8000/analyze" \
101
- -H "accept: application/json" \
102
- -H "Content-Type: multipart/form-data" \
103
- -F "file=@your_lab_report.jpg"
104
- ```
105
-
106
- 3. **Analyze base64 image:**
107
- ```bash
108
- curl -X POST "http://localhost:8000/analyze-base64" \
109
- -H "Content-Type: application/json" \
110
- -d '{"image": "your_base64_encoded_image_here"}'
111
- ```
112
-
113
- ### Using Python Test Client
114
-
115
- ```python
116
- from test_client import LabReportAPIClient
117
-
118
- client = LabReportAPIClient()
119
-
120
- # Health check
121
- health = client.health_check()
122
- print(health)
123
-
124
- # Analyze image
125
- result = client.analyze_image_file("path/to/your/lab_report.jpg")
126
- print(result)
127
- ```
128
-
129
- ### Using the Web Interface
130
-
131
- 1. Start the API server
132
- 2. Open `index.html` in your web browser
133
- 3. Drag and drop or select a lab report image
134
- 4. Click "Analyze Report" to get results
135
-
136
- ## Response Format
137
-
138
- Successful analysis returns:
139
-
140
- ```json
141
- {
142
- "success": true,
143
- "filename": "lab_report.jpg",
144
- "analysis": {
145
- "error": false,
146
- "summary": "Brief summary of the lab report",
147
- "key_findings": ["Finding 1", "Finding 2", "Finding 3"],
148
- "interpretation": "Medical interpretation",
149
- "note": "Disclaimer about medical advice",
150
- "raw_response": "Complete AI response"
151
- }
152
- }
153
- ```
154
-
155
- ## Configuration
156
-
157
- ### Environment Variables
158
-
159
- You can set these environment variables to customize the behavior:
160
-
161
- - `API_HOST`: Host to bind to (default: "0.0.0.0")
162
- - `API_PORT`: Port to bind to (default: 8000)
163
- - `HF_API_KEY`: Hugging Face API key (currently hardcoded in `lab_analyzer.py`)
164
-
165
- ### Updating API Key
166
-
167
- To use your own Hugging Face API key, modify the `lab_analyzer.py` file:
168
-
169
- ```python
170
- self.client = InferenceClient(
171
- provider="nebius",
172
- api_key="your_api_key_here", # Replace with your API key
173
- )
174
- ```
175
-
176
- ## Development
177
-
178
- ### Running in Development Mode
179
-
180
- ```bash
181
- uvicorn main:app --reload --host 0.0.0.0 --port 8000
182
- ```
183
-
184
- ### Testing
185
-
186
- Run the test client:
187
-
188
- ```bash
189
- python test_client.py
190
- ```
191
-
192
- ### Adding New Features
193
-
194
- 1. Add new endpoints to `main.py`
195
- 2. Update models in `models.py` if needed
196
- 3. Extend the analyzer in `lab_analyzer.py`
197
- 4. Update documentation
198
-
199
- ## Deployment
200
-
201
- ### Docker (Optional)
202
-
203
- Create a `Dockerfile`:
204
-
205
- ```dockerfile
206
- FROM python:3.9-slim
207
-
208
- WORKDIR /app
209
- COPY requirements.txt .
210
- RUN pip install -r requirements.txt
211
-
212
- COPY . .
213
-
214
- EXPOSE 8000
215
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
216
- ```
217
-
218
- Build and run:
219
-
220
- ```bash
221
- docker build -t lab-analysis-api .
222
- docker run -p 8000:8000 lab-analysis-api
223
- ```
224
-
225
- ### Production Considerations
226
-
227
- - Use environment variables for API keys
228
- - Set up proper CORS origins
229
- - Add rate limiting
230
- - Use HTTPS
231
- - Add authentication if needed
232
- - Set up logging and monitoring
233
-
234
- ## Troubleshooting
235
-
236
- ### Common Issues
237
-
238
- 1. **Import errors**: Make sure all dependencies are installed
239
- 2. **Port conflicts**: Change the port in the uvicorn command
240
- 3. **API key issues**: Verify your Hugging Face API key is valid
241
- 4. **Image format errors**: Ensure images are in supported formats
242
-
243
- ### Logs
244
-
245
- The application logs important events. Check console output for debugging information.
246
-
247
- ## License
248
-
249
- This project is for educational purposes. Please ensure you have proper licenses for any AI models used.
250
-
251
- ## Contributing
252
-
253
- 1. Fork the repository
254
- 2. Create a feature branch
255
- 3. Make your changes
256
- 4. Test thoroughly
257
- 5. Submit a pull request
258
-
259
- ---
260
-
261
- **Note**: This analysis is for educational purposes only and should not replace professional medical advice.
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: GP-Tea Lab Analysis
3
+ emoji: πŸ§ͺ
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: docker
7
+ app_port: 7860
8
+ pinned: false
9
+ license: apache-2.0
10
+ ---
11
+
12
+ # GP-Tea Lab Analysis Service
13
+
14
+ A FastAPI-based web service for analyzing lab report images using AI. This service accepts lab report images and provides structured medical analysis with key findings, interpretations, and health insights.
15
+
16
+ ## Features
17
+
18
+ - πŸ–ΌοΈ Image upload support (JPG, PNG, BMP, TIFF, WEBP)
19
+ - πŸ” AI-powered lab report analysis
20
+ - πŸ“Š Structured response with summary, key findings, and interpretation
21
+ - 🌐 RESTful API with automatic documentation
22
+ - πŸ§ͺ Built-in test client and web interface
23
+ - ⚑ Async processing for better performance
24
+
25
+ ## Project Structure
26
+
27
+ ```
28
+ Lab_analysis/
29
+ β”œβ”€β”€ main.py # FastAPI application
30
+ β”œβ”€β”€ lab_analyzer.py # Core analysis logic
31
+ β”œβ”€β”€ models.py # Pydantic models
32
+ β”œβ”€β”€ test_client.py # API test client
33
+ β”œβ”€β”€ index.html # Web interface
34
+ β”œβ”€β”€ requirements.txt # Dependencies
35
+ β”œβ”€β”€ Lab_report_analysis.py # Original script
36
+ └── README.md # This file
37
+ ```
38
+
39
+ ## Installation
40
+
41
+ 1. **Clone or navigate to the project directory:**
42
+
43
+ ```bash
44
+ cd "e:\E-JUST Assignments\Projects\HealthCare\Lab_analysis"
45
+ ```
46
+
47
+ 2. **Create a virtual environment (recommended):**
48
+
49
+ ```bash
50
+ python -m venv venv
51
+ venv\Scripts\activate # On Windows
52
+ ```
53
+
54
+ 3. **Install dependencies:**
55
+ ```bash
56
+ pip install -r requirements.txt
57
+ ```
58
+
59
+ ## Running the API
60
+
61
+ ### Method 1: Using Python directly
62
+
63
+ ```bash
64
+ python main.py
65
+ ```
66
+
67
+ ### Method 2: Using Uvicorn
68
+
69
+ ```bash
70
+ uvicorn main:app --host 0.0.0.0 --port 8000 --reload
71
+ ```
72
+
73
+ The API will be available at:
74
+
75
+ - **API Endpoints**: http://localhost:8000
76
+ - **Interactive Docs**: http://localhost:8000/docs
77
+ - **ReDoc**: http://localhost:8000/redoc
78
+
79
+ ## API Endpoints
80
+
81
+ ### Health Check
82
+
83
+ - **GET** `/health`
84
+ - Returns service status
85
+
86
+ ### Analyze Lab Report (File Upload)
87
+
88
+ - **POST** `/analyze`
89
+ - Upload an image file for analysis
90
+ - Accepts: `multipart/form-data` with `file` field
91
+
92
+ ### Analyze Lab Report (Base64)
93
+
94
+ - **POST** `/analyze-base64`
95
+ - Send base64 encoded image for analysis
96
+ - Accepts: JSON with `image` field containing base64 string
97
+
98
+ ## Usage Examples
99
+
100
+ ### Using cURL
101
+
102
+ 1. **Health check:**
103
+
104
+ ```bash
105
+ curl http://localhost:8000/health
106
+ ```
107
+
108
+ 2. **Analyze image file:**
109
+
110
+ ```bash
111
+ curl -X POST "http://localhost:8000/analyze" \
112
+ -H "accept: application/json" \
113
+ -H "Content-Type: multipart/form-data" \
114
+ -F "file=@your_lab_report.jpg"
115
+ ```
116
+
117
+ 3. **Analyze base64 image:**
118
+ ```bash
119
+ curl -X POST "http://localhost:8000/analyze-base64" \
120
+ -H "Content-Type: application/json" \
121
+ -d '{"image": "your_base64_encoded_image_here"}'
122
+ ```
123
+
124
+ ### Using Python Test Client
125
+
126
+ ```python
127
+ from test_client import LabReportAPIClient
128
+
129
+ client = LabReportAPIClient()
130
+
131
+ # Health check
132
+ health = client.health_check()
133
+ print(health)
134
+
135
+ # Analyze image
136
+ result = client.analyze_image_file("path/to/your/lab_report.jpg")
137
+ print(result)
138
+ ```
139
+
140
+ ### Using the Web Interface
141
+
142
+ 1. Start the API server
143
+ 2. Open `index.html` in your web browser
144
+ 3. Drag and drop or select a lab report image
145
+ 4. Click "Analyze Report" to get results
146
+
147
+ ## Response Format
148
+
149
+ Successful analysis returns:
150
+
151
+ ```json
152
+ {
153
+ "success": true,
154
+ "filename": "lab_report.jpg",
155
+ "analysis": {
156
+ "error": false,
157
+ "summary": "Brief summary of the lab report",
158
+ "key_findings": ["Finding 1", "Finding 2", "Finding 3"],
159
+ "interpretation": "Medical interpretation",
160
+ "note": "Disclaimer about medical advice",
161
+ "raw_response": "Complete AI response"
162
+ }
163
+ }
164
+ ```
165
+
166
+ ## Configuration
167
+
168
+ ### Environment Variables
169
+
170
+ You can set these environment variables to customize the behavior:
171
+
172
+ - `API_HOST`: Host to bind to (default: "0.0.0.0")
173
+ - `API_PORT`: Port to bind to (default: 8000)
174
+ - `HF_API_KEY`: Hugging Face API key (currently hardcoded in `lab_analyzer.py`)
175
+
176
+ ### Updating API Key
177
+
178
+ To use your own Hugging Face API key, modify the `lab_analyzer.py` file:
179
+
180
+ ```python
181
+ self.client = InferenceClient(
182
+ provider="nebius",
183
+ api_key="your_api_key_here", # Replace with your API key
184
+ )
185
+ ```
186
+
187
+ ## Development
188
+
189
+ ### Running in Development Mode
190
+
191
+ ```bash
192
+ uvicorn main:app --reload --host 0.0.0.0 --port 8000
193
+ ```
194
+
195
+ ### Testing
196
+
197
+ Run the test client:
198
+
199
+ ```bash
200
+ python test_client.py
201
+ ```
202
+
203
+ ### Adding New Features
204
+
205
+ 1. Add new endpoints to `main.py`
206
+ 2. Update models in `models.py` if needed
207
+ 3. Extend the analyzer in `lab_analyzer.py`
208
+ 4. Update documentation
209
+
210
+ ## Deployment
211
+
212
+ ### Docker (Optional)
213
+
214
+ Create a `Dockerfile`:
215
+
216
+ ```dockerfile
217
+ FROM python:3.9-slim
218
+
219
+ WORKDIR /app
220
+ COPY requirements.txt .
221
+ RUN pip install -r requirements.txt
222
+
223
+ COPY . .
224
+
225
+ EXPOSE 8000
226
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
227
+ ```
228
+
229
+ Build and run:
230
+
231
+ ```bash
232
+ docker build -t lab-analysis-api .
233
+ docker run -p 8000:8000 lab-analysis-api
234
+ ```
235
+
236
+ ### Production Considerations
237
+
238
+ - Use environment variables for API keys
239
+ - Set up proper CORS origins
240
+ - Add rate limiting
241
+ - Use HTTPS
242
+ - Add authentication if needed
243
+ - Set up logging and monitoring
244
+
245
+ ## Troubleshooting
246
+
247
+ ### Common Issues
248
+
249
+ 1. **Import errors**: Make sure all dependencies are installed
250
+ 2. **Port conflicts**: Change the port in the uvicorn command
251
+ 3. **API key issues**: Verify your Hugging Face API key is valid
252
+ 4. **Image format errors**: Ensure images are in supported formats
253
+
254
+ ### Logs
255
+
256
+ The application logs important events. Check console output for debugging information.
257
+
258
+ ## License
259
+
260
+ This project is for educational purposes. Please ensure you have proper licenses for any AI models used.
261
+
262
+ ## Contributing
263
+
264
+ 1. Fork the repository
265
+ 2. Create a feature branch
266
+ 3. Make your changes
267
+ 4. Test thoroughly
268
+ 5. Submit a pull request
269
+
270
+ ---
271
+
272
+ **Note**: This analysis is for educational purposes only and should not replace professional medical advice.