🎉 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}")