Views
No views yet
A: dyed-lifted-polypsB: dyed-resection-marginsC: esophagitisD: normal-cecumE: normal-pylorusF: normal-z-lineG: polypsH: ulcerative-colitiscontent array. Here is how to load and run inference:1import torch
2from transformers import pipeline
3from PIL import Image
4import requests
5
6# 1. Load the Model
7pipe = pipeline(
8 "image-text-to-text",
9 model="umakantcurateai/medgemma-kvasir-finetune-umak",
10 torch_dtype=torch.bfloat16,
11 device_map="auto"
12)
13pipe.model.generation_config.do_sample = False
14pipe.processor.tokenizer.padding_side = "left"
15
16# 2. Load an Endoscopy Image
17url = "[https://example.com/path_to_endoscopy_image.jpg](https://example.com/path_to_endoscopy_image.jpg)" # Replace with your image
18image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
19
20# 3. Define the Prompt & Multiple Choice Options
21PROMPT = """What is the most likely endoscopic finding or anatomical landmark shown in this image?
22A: dyed-lifted-polyps
23B: dyed-resection-margins
24C: esophagitis
25D: normal-cecum
26E: normal-pylorus
27F: normal-z-line
28G: polyps
29H: ulcerative-colitis"""
30
31messages = [
32 {
33 "role": "user",
34 "content": [
35 {"type": "image", "image": image},
36 {"type": "text", "text": PROMPT}
37 ]
38 }
39]
40
41# 4. Generate Classification
42output = pipe(messages, max_new_tokens=20, return_full_text=False)
43print(f"Predicted Class: {output[0]['generated_text']}")