Simplify to minimal backend API
Browse files- Remove unnecessary UI elements (examples, article, theme)
- Simplify interface for API-focused use
- Update README with API usage documentation
- Add API endpoint information and examples
- Remove unused imports
README.md
CHANGED
|
@@ -10,35 +10,53 @@ pinned: false
|
|
| 10 |
license: apache-2.0
|
| 11 |
---
|
| 12 |
|
| 13 |
-
# 🫀 ECG AI7
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
-
##
|
| 18 |
|
| 19 |
-
|
| 20 |
-
- **Bilingual Support**: Generate reports in both English and Farsi (Persian)
|
| 21 |
-
- **Clinical Context**: Add patient information for more personalized interpretations
|
| 22 |
-
- **User-Friendly Interface**: Simple upload and analyze workflow
|
| 23 |
|
| 24 |
-
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
2. Optionally add patient information or clinical notes
|
| 28 |
-
3. Select your preferred output language (English or Farsi)
|
| 29 |
-
4. Click Submit and wait for the AI analysis
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
## Model
|
| 36 |
|
| 37 |
-
|
| 38 |
|
| 39 |
-
##
|
| 40 |
|
| 41 |
-
|
| 42 |
-
- **Framework**: PyTorch + Transformers
|
| 43 |
-
- **Interface**: Gradio
|
| 44 |
-
- **Languages**: English, Farsi (Persian)
|
|
|
|
| 10 |
license: apache-2.0
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# 🫀 ECG AI7 Backend API
|
| 14 |
|
| 15 |
+
Backend API for ECG interpretation using Llama 3.2 11B Vision model.
|
| 16 |
|
| 17 |
+
## API Usage
|
| 18 |
|
| 19 |
+
### Using Python Client
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
```python
|
| 22 |
+
from gradio_client import Client, handle_file
|
| 23 |
|
| 24 |
+
client = Client("AKSazgar/ECG-Instruct-Llama-3.2-11B-Vision")
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
result = client.predict(
|
| 27 |
+
handle_file("path/to/ecg.jpg"), # ECG image
|
| 28 |
+
"55-year-old male with chest pain", # Clinical note (optional)
|
| 29 |
+
"Farsi", # Language: "English" or "Farsi"
|
| 30 |
+
api_name="/predict"
|
| 31 |
+
)
|
| 32 |
|
| 33 |
+
print(result)
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
### Using Command Line
|
| 37 |
+
|
| 38 |
+
```bash
|
| 39 |
+
python ecg_client_alt.py \
|
| 40 |
+
--url https://aksazgar-ecg-instruct-llama-3-2-11b-vision.hf.space \
|
| 41 |
+
--input ecg-images/example.jpg \
|
| 42 |
+
--text "Patient clinical notes" \
|
| 43 |
+
--lang Farsi
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
## API Endpoint
|
| 47 |
+
|
| 48 |
+
- **Space URL**: `https://aksazgar-ecg-instruct-llama-3-2-11b-vision.hf.space`
|
| 49 |
+
- **API Name**: `/predict`
|
| 50 |
+
- **Inputs**:
|
| 51 |
+
- Image file (ECG)
|
| 52 |
+
- Text (clinical notes, optional)
|
| 53 |
+
- Language ("English" or "Farsi")
|
| 54 |
+
- **Output**: Text (ECG interpretation report)
|
| 55 |
|
| 56 |
## Model
|
| 57 |
|
| 58 |
+
Uses [ECG-Instruct-Llama-3.2-11B-Vision](https://huggingface.co/convaiinnovations/ECG-Instruct-Llama-3.2-11B-Vision) by ConvAI Innovations.
|
| 59 |
|
| 60 |
+
## Disclaimer
|
| 61 |
|
| 62 |
+
⚠️ For educational and research purposes only. Not for clinical use.
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -8,7 +8,6 @@ import torch
|
|
| 8 |
from transformers import MllamaForConditionalGeneration, AutoProcessor, TextStreamer
|
| 9 |
from PIL import Image
|
| 10 |
import gradio as gr
|
| 11 |
-
import os
|
| 12 |
|
| 13 |
# Model configuration
|
| 14 |
MODEL_ID = "convaiinnovations/ECG-Instruct-Llama-3.2-11B-Vision"
|
|
@@ -169,62 +168,18 @@ def analyze_ecg_gradio(image, text_instruction="", language="Farsi"):
|
|
| 169 |
return error_msg
|
| 170 |
|
| 171 |
|
| 172 |
-
# Create Gradio interface
|
| 173 |
demo = gr.Interface(
|
| 174 |
fn=analyze_ecg_gradio,
|
| 175 |
inputs=[
|
| 176 |
gr.Image(type="filepath", label="ECG Image"),
|
| 177 |
-
gr.Textbox(
|
| 178 |
-
|
| 179 |
-
placeholder="Optional: Enter patient info or clinical notes (e.g., '55-year-old male with chest pain')",
|
| 180 |
-
label="Clinical Note"
|
| 181 |
-
),
|
| 182 |
-
gr.Dropdown(
|
| 183 |
-
choices=["English", "Farsi"],
|
| 184 |
-
value="Farsi",
|
| 185 |
-
label="Output Language"
|
| 186 |
-
),
|
| 187 |
],
|
| 188 |
-
outputs=gr.Textbox(
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
),
|
| 193 |
-
title="🫀 ECG AI7 - Intelligent ECG Interpretation",
|
| 194 |
-
description="""
|
| 195 |
-
Upload an ECG image to get an AI-powered interpretation.
|
| 196 |
-
|
| 197 |
-
**Features:**
|
| 198 |
-
- Advanced ECG analysis using Llama 3.2 11B Vision
|
| 199 |
-
- Support for English and Farsi (Persian) output
|
| 200 |
-
- Optional patient context for more personalized reports
|
| 201 |
-
|
| 202 |
-
**Note:** This is an AI assistant tool and should not replace professional medical diagnosis.
|
| 203 |
-
""",
|
| 204 |
-
examples=[
|
| 205 |
-
["example_ecg.jpg", "55-year-old male with chest pain", "English"],
|
| 206 |
-
["example_ecg.jpg", "بیمار 55 ساله مرد با درد قفسه سینه", "Farsi"],
|
| 207 |
-
] if os.path.exists("example_ecg.jpg") else None,
|
| 208 |
-
article="""
|
| 209 |
-
### About
|
| 210 |
-
This application uses a fine-tuned Llama 3.2 11B Vision model specifically trained for ECG interpretation.
|
| 211 |
-
|
| 212 |
-
### How to Use
|
| 213 |
-
1. Upload an ECG image (12-lead ECG works best)
|
| 214 |
-
2. Optionally add patient information or clinical context
|
| 215 |
-
3. Select your preferred output language (English or Farsi)
|
| 216 |
-
4. Click Submit and wait for the AI analysis
|
| 217 |
-
|
| 218 |
-
### Important Disclaimer
|
| 219 |
-
This tool is for educational and research purposes. Always consult with qualified healthcare
|
| 220 |
-
professionals for medical decisions. AI-generated interpretations should be verified by licensed
|
| 221 |
-
cardiologists.
|
| 222 |
-
|
| 223 |
-
---
|
| 224 |
-
Model: [ECG-Instruct-Llama-3.2-11B-Vision](https://huggingface.co/convaiinnovations/ECG-Instruct-Llama-3.2-11B-Vision) by ConvAI Innovations
|
| 225 |
-
""",
|
| 226 |
-
theme=gr.themes.Soft(),
|
| 227 |
-
allow_flagging="never",
|
| 228 |
)
|
| 229 |
|
| 230 |
# Launch the app
|
|
|
|
| 8 |
from transformers import MllamaForConditionalGeneration, AutoProcessor, TextStreamer
|
| 9 |
from PIL import Image
|
| 10 |
import gradio as gr
|
|
|
|
| 11 |
|
| 12 |
# Model configuration
|
| 13 |
MODEL_ID = "convaiinnovations/ECG-Instruct-Llama-3.2-11B-Vision"
|
|
|
|
| 168 |
return error_msg
|
| 169 |
|
| 170 |
|
| 171 |
+
# Create minimal Gradio interface for API backend
|
| 172 |
demo = gr.Interface(
|
| 173 |
fn=analyze_ecg_gradio,
|
| 174 |
inputs=[
|
| 175 |
gr.Image(type="filepath", label="ECG Image"),
|
| 176 |
+
gr.Textbox(lines=2, label="Clinical Note (Optional)"),
|
| 177 |
+
gr.Dropdown(choices=["English", "Farsi"], value="Farsi", label="Language"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
],
|
| 179 |
+
outputs=gr.Textbox(label="ECG Report", lines=15),
|
| 180 |
+
title="ECG AI7 Backend",
|
| 181 |
+
description="ECG interpretation API powered by Llama 3.2 11B Vision",
|
| 182 |
+
flagging_mode="never",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
)
|
| 184 |
|
| 185 |
# Launch the app
|