Image-Text-to-Text
Transformers
ONNX
Safetensors
English
medical
chest-xray
radiology
clip
blip
multimodal
cpu
Instructions to use GAD-Research-Lab/MedicalAI-Light-Weight with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use GAD-Research-Lab/MedicalAI-Light-Weight with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="GAD-Research-Lab/MedicalAI-Light-Weight")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("GAD-Research-Lab/MedicalAI-Light-Weight", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use GAD-Research-Lab/MedicalAI-Light-Weight with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "GAD-Research-Lab/MedicalAI-Light-Weight" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "GAD-Research-Lab/MedicalAI-Light-Weight", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/GAD-Research-Lab/MedicalAI-Light-Weight
- SGLang
How to use GAD-Research-Lab/MedicalAI-Light-Weight with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "GAD-Research-Lab/MedicalAI-Light-Weight" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "GAD-Research-Lab/MedicalAI-Light-Weight", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "GAD-Research-Lab/MedicalAI-Light-Weight" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "GAD-Research-Lab/MedicalAI-Light-Weight", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use GAD-Research-Lab/MedicalAI-Light-Weight with Docker Model Runner:
docker model run hf.co/GAD-Research-Lab/MedicalAI-Light-Weight
| import importlib | |
| import os | |
| import subprocess | |
| import sys | |
| import tempfile | |
| from datetime import datetime | |
| from pathlib import Path | |
| from PIL import Image, ImageOps | |
| DATA_DIR = Path("./data") | |
| IMAGES_DIR = DATA_DIR / "images" | |
| def _ensure_dep(package_name, import_name=None): | |
| if import_name is None: | |
| import_name = package_name | |
| try: | |
| return importlib.import_module(import_name) | |
| except ImportError: | |
| from rich.console import Console | |
| console = Console() | |
| console.print(f"[yellow]'{package_name}' is required for this feature.[/yellow]") | |
| import questionary | |
| install = questionary.confirm(f"Install {package_name} now?", default=True).ask() | |
| if not install: | |
| return None | |
| console.print(f"[cyan]Installing {package_name}...[/cyan]") | |
| subprocess.check_call([sys.executable, "-m", "pip", "install", package_name]) | |
| return importlib.import_module(import_name) | |
| def _ensure_dirs(): | |
| IMAGES_DIR.mkdir(parents=True, exist_ok=True) | |
| def _save_image(pil_image, prefix="capture"): | |
| _ensure_dirs() | |
| timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f") | |
| filename = f"{prefix}_{timestamp}.jpg" | |
| path = str(IMAGES_DIR / filename) | |
| if pil_image.mode != "RGB": | |
| pil_image = pil_image.convert("RGB") | |
| pil_image.save(path, quality=95) | |
| return path | |
| # ββ Camera ββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| def capture_camera(): | |
| cv2 = _ensure_dep("opencv-python", "cv2") | |
| if cv2 is None: | |
| return None, "Camera capture requires opencv-python" | |
| cap = cv2.VideoCapture(0) | |
| if not cap.isOpened(): | |
| return None, "No camera detected (could not open index 0)" | |
| from rich.console import Console | |
| console = Console() | |
| console.print("[cyan]Camera opened. Press SPACE to capture, ESC to cancel.[/cyan]") | |
| import questionary | |
| input("Press Enter when ready for camera preview...") | |
| ret, frame = cap.read() | |
| cap.release() | |
| if not ret: | |
| return None, "Failed to capture frame from camera" | |
| preview_path = tempfile.mktemp(suffix="_preview.jpg") | |
| cv2.imwrite(preview_path, frame) | |
| preview = Image.open(preview_path) | |
| os.unlink(preview_path) | |
| console.print("[cyan]Image captured from camera.[/cyan]") | |
| path = _save_image(preview, "camera") | |
| return path, f"Captured from camera -> {path}" | |
| # ββ File browser βββββββββββββββββββββββββββββββββββββββββββββββ | |
| def capture_file(): | |
| try: | |
| import tkinter as tk | |
| from tkinter import filedialog | |
| root = tk.Tk() | |
| root.withdraw() | |
| root.attributes("-topmost", True) | |
| path = filedialog.askopenfilename( | |
| title="Select an X-ray image", | |
| filetypes=[ | |
| ("Image files", "*.jpg *.jpeg *.png *.bmp *.tif *.tiff *.dcm"), | |
| ("All files", "*.*"), | |
| ], | |
| ) | |
| root.destroy() | |
| except Exception as e: | |
| return None, f"File dialog failed: {e}" | |
| if not path: | |
| return None, "No file selected" | |
| return _open_and_save(path) | |
| # ββ Manual path entry ββββββββββββββββββββββββββββββββββββββββββ | |
| def capture_path(): | |
| from rich.console import Console | |
| console = Console() | |
| console.print("[cyan]Enter the path to an X-ray image file.[/cyan]") | |
| import questionary | |
| path = questionary.path("Image path:").ask() | |
| if not path: | |
| return None, "No path entered" | |
| return _open_and_save(path) | |
| # ββ DICOM ββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| def capture_dicom(path=None): | |
| pydicom = _ensure_dep("pydicom") | |
| if pydicom is None: | |
| return None, "DICOM loading requires pydicom" | |
| np = _ensure_dep("numpy") | |
| if np is None: | |
| return None, "DICOM loading requires numpy" | |
| if not path: | |
| try: | |
| import tkinter as tk | |
| from tkinter import filedialog | |
| root = tk.Tk() | |
| root.withdraw() | |
| root.attributes("-topmost", True) | |
| path = filedialog.askopenfilename( | |
| title="Select a DICOM file", | |
| filetypes=[("DICOM files", "*.dcm"), ("All files", "*.*")], | |
| ) | |
| root.destroy() | |
| except Exception as e: | |
| return None, f"File dialog failed: {e}" | |
| if not path: | |
| return None, "No DICOM file selected" | |
| try: | |
| ds = pydicom.dcmread(path) | |
| arr = ds.pixel_array | |
| arr = arr - arr.min() | |
| arr = (arr / arr.max() * 255).astype(np.uint8) | |
| if len(arr.shape) == 2: | |
| img = Image.fromarray(arr, mode="L") | |
| img = ImageOps.equalize(img) | |
| else: | |
| img = Image.fromarray(arr) | |
| result_path = _save_image(img, "dicom") | |
| return result_path, f"DICOM loaded from {path} -> saved as {result_path}" | |
| except Exception as e: | |
| return None, f"Failed to read DICOM: {e}" | |
| # ββ Generic open + save ββββββββββββββββββββββββββββββββββββββββ | |
| def _open_and_save(source_path): | |
| source_path = str(source_path) | |
| if source_path.lower().endswith(".dcm"): | |
| return capture_dicom(source_path) | |
| try: | |
| img = Image.open(source_path) | |
| path = _save_image(img, "import") | |
| return path, f"Imported from {source_path} -> {path}" | |
| except Exception as e: | |
| return None, f"Failed to open image: {e}" | |
| # ββ Top-level picker βββββββββββββββββββββββββββββββββββββββββββ | |
| def pick_image(): | |
| from rich.console import Console | |
| import questionary | |
| console = Console() | |
| method = questionary.select( | |
| "How do you want to provide the X-ray image?", | |
| choices=[ | |
| "Browse files on computer", | |
| "Enter file path manually", | |
| "Capture from camera", | |
| "Load DICOM file", | |
| ], | |
| pointer=">", | |
| ).ask() | |
| result = None | |
| if method == "Browse files on computer": | |
| result = capture_file() | |
| elif method == "Enter file path manually": | |
| result = capture_path() | |
| elif method == "Capture from camera": | |
| result = capture_camera() | |
| elif method == "Load DICOM file": | |
| result = capture_dicom() | |
| return result | |
| if __name__ == "__main__": | |
| path, msg = pick_image() | |
| print(msg) | |