🎉 30% OFF Pro Plan立即獲取
Medical AI Background

API 存取

MedGemma 與 MedSigLIP API 使用指南

透過全面的 API 存取開始使用 Google 的醫療 AI 模型。申請 API 金鑰並將先進的醫療 AI 功能整合到您的應用程式中。

申請 API 存取

開始使用 MedGemma 和 MedSigLIP API

MedGemma API

先進的醫療文字和多模態 AI 模型

存取 MedGemma 強大的醫療文字分析、影像理解和臨床決策支援功能。

核心功能

  • 醫療文字生成和分析
  • 多模態醫療影像和文字處理
  • 臨床問答
  • 醫療報告生成
  • 微調功能

可用模型

MedGemma 4B 多模態

用於醫療影像和文字任務的輕量級模型

40 億參數

MedGemma 27B 純文字

專門用於醫療文字的大型語言模型

270 億參數

MedGemma 27B 多模態

用於複雜醫療任務的先進多模態模型

270 億參數

MedSigLIP API

用於分類和檢索的醫療影像文字編碼器

利用 MedSigLIP 高效的雙塔架構進行醫療影像分類、零樣本推理和語義檢索。

核心功能

  • 零樣本醫療影像分類
  • 語義影像檢索
  • 醫療影像嵌入
  • 資料高效分類
  • 跨模態相似性搜尋

模型規格

參數量:4 億參數
影像尺寸:448×448 像素
文字長度:最多 64 個標記
架構:雙塔編碼器(視覺 + 文字)

部署選項

選擇最適合您需求的部署方法

本地部署

使用 Hugging Face transformers 在本地執行模型

Pros:

  • +完全控制
  • +無 API 限制
  • +資料隱私

Cons:

  • -需要 GPU 資源
  • -設定複雜
Best for: 開發和測試

Vertex AI 部署

在 Google Cloud 上部署為 REST API 端點

Pros:

  • +可擴展
  • +託管基礎設施
  • +生產就緒

Cons:

  • -使用成本
  • -雲端依賴
Best for: 生產應用程式

批次處理

使用 Vertex AI 批次作業處理大型資料集

Pros:

  • +成本效益
  • +大規模處理

Cons:

  • -非即時
  • -批次排程
Best for: 大量資料處理

Code Examples

Get started with implementation examples

MedGemma Implementation

Local Deployment

from transformers import pipeline

# Load MedGemma model
pipe = pipeline(
    "text-generation",
    model="google/medgemma-27b-text-it",
    torch_dtype="bfloat16",
    device="cuda"
)

# Generate medical text
response = pipe(
    "What are the symptoms of diabetes?",
    max_length=200,
    temperature=0.7
)

print(response[0]['generated_text'])

Vertex AI REST API

import requests
import json

# Vertex AI endpoint
endpoint_url = "https://your-endpoint.googleapis.com/v1/projects/your-project/locations/us-central1/endpoints/your-endpoint:predict"

# Request payload
payload = {
    "instances": [{
        "prompt": "What are the symptoms of diabetes?",
        "max_tokens": 200,
        "temperature": 0.7
    }]
}

# Make API request
headers = {
    "Authorization": "Bearer YOUR_ACCESS_TOKEN",
    "Content-Type": "application/json"
}

response = requests.post(endpoint_url, json=payload, headers=headers)
result = response.json()

print(result['predictions'][0]['generated_text'])

MedSigLIP Implementation

Local Deployment

from transformers import AutoModel, AutoProcessor
import torch
from PIL import Image

# Load MedSigLIP model
model = AutoModel.from_pretrained("google/medsiglip")
processor = AutoProcessor.from_pretrained("google/medsiglip")

# Load and process image
image = Image.open("medical_image.jpg")
text = "chest x-ray showing pneumonia"

# Process inputs
inputs = processor(
    text=[text],
    images=[image],
    return_tensors="pt",
    padding=True
)

# Get embeddings
with torch.no_grad():
    outputs = model(**inputs)
    image_embeds = outputs.image_embeds
    text_embeds = outputs.text_embeds

# Calculate similarity
similarity = torch.cosine_similarity(image_embeds, text_embeds)
print(f"Similarity score: {similarity.item():.4f}")

Zero-shot Classification

import torch
from transformers import AutoModel, AutoProcessor
from PIL import Image

# Load model and processor
model = AutoModel.from_pretrained("google/medsiglip")
processor = AutoProcessor.from_pretrained("google/medsiglip")

# Define classification labels
labels = [
    "normal chest x-ray",
    "pneumonia chest x-ray",
    "covid-19 chest x-ray",
    "lung cancer chest x-ray"
]

# Load image
image = Image.open("chest_xray.jpg")

# Process inputs
inputs = processor(
    text=labels,
    images=[image] * len(labels),
    return_tensors="pt",
    padding=True
)

# Get predictions
with torch.no_grad():
    outputs = model(**inputs)
    logits = outputs.logits_per_image
    probs = torch.softmax(logits, dim=-1)

# Get top prediction
top_idx = torch.argmax(probs, dim=-1)
confidence = probs[0, top_idx].item()

print(f"Prediction: {labels[top_idx]}")
print(f"Confidence: {confidence:.4f}")