Views
No views yet
1from transformers import pipeline
2from PIL import Image
3import requests
4import torch
5
6pipe = pipeline(
7 "image-text-to-text",
8 model="gbalachandhiran/medgemma-Histopathology-lung-colon",
9 torch_dtype=torch.bfloat16,
10 device="cuda",
11)
12## Lung cancer sample
13image_url = "https://cdnintech.com/media/chapter/59926/1512345123/media/F1.png"
14image = Image.open(requests.get(image_url, headers={"User-Agent": "example"}, stream=True).raw)
15
16TISSUE_CLASSES = [
17 "A: colon_aca",
18 "B: colon_n",
19 "C: lung_aca",
20 "D: lung_n",
21 "E: lung_scc"
22]
23
24options = "\n".join(TISSUE_CLASSES)
25PROMPT = f"What is the most likely tissue type shown in the histopathology image?\n{options}"''
26
27messages = [
28 {
29 "role": "system",
30 "content": [{"type": "text", "text": "You are an expert radiologist."}]
31 },
32 {
33 "role": "user",
34 "content": [
35 {"type": "text", "text": PROMPT},
36 {"type": "image", "image": image},
37 ]
38 }
39]
40
41output = pipe(text=messages, max_new_tokens=50)
42print(output[0]["generated_text"][-1]["content"])1@misc{vonwerra2022trl,
2 title = {{Fine Tuning Medgemma to identify Histopathology images of lungs and Colon}},
3 author = {Dr. Ramanan. R. K:dr.ramanan.r.k@c-riht.org,Dhanu Elavarasan : nreldhanu1713@gmail.com,Gowtham Balachadhiran:gowthambalachandhiran@gmail.com},
4 year = 2025,
5 journal = {[GitHub repository](https://github.com/gowthambalachandhiran/MedGemmaAUKBC)},
6 publisher = {GitHub},
7 howpublished = {\url{gbalachandhiran/medgemma-Histopathology-lung-colon}}
8}