Spaces:
Sleeping
Sleeping
File size: 738 Bytes
1a6388d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import gradio as gr
import torch
from transformers import pipeline
from PIL import Image
import os
# Load model using the secret token
token = os.getenv("HF_TOKEN")
pipe = pipeline("image-text-to-text",
model="google/medgemma-4b-it",
torch_dtype=torch.bfloat16,
token=token,
device_map="auto")
def analyze(img):
messages = [{"role": "user", "content": [{"type": "image", "image": img}, {"type": "text", "text": "Analyze this pediatric CXR."}]}]
output = pipe(text=messages, max_new_tokens=256)
return output[0]['generated_text'][-1]['content']
demo = gr.Interface(fn=analyze, inputs=gr.Image(type="pil"), outputs="text", title="MedGemma CXR")
demo.launch() |