Spaces:
Sleeping
Sleeping
Download app.py from adiafiq/X-Ray_Reporting_AI: direct link, hf CLI and curl.
- Browser
- Download file 738 Bytes
-
https://huggingface.co/spaces/adiafiq/X-Ray_Reporting_AI/resolve/main/app.py
- Command line
-
hf download hf://spaces/adiafiq/X-Ray_Reporting_AI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/adiafiq/X-Ray_Reporting_AI/resolve/main/app.py
738 Bytes
| 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() |