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()