Views
No views yet
! pip install -q "flash_attn==2.6.3" "timm==1.0.8" "einops==0.8.0" "transformers==4.44.0" 1device = "cuda:0" if torch.cuda.is_available() else "cpu"
2torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float321model = AutoModelForCausalLM.from_pretrained("nirusanan/Florence-2_FT_Lung-Cancer-detection", torch_dtype=torch_dtype, trust_remote_code=True).to(device)
2processor = AutoProcessor.from_pretrained("nirusanan/Florence-2_FT_Lung-Cancer-detection", trust_remote_code=True)1prompt = "<DocVQA>" + "What is the type of lung cancer?"
2
3url = "https://www.uab.edu/news/images/ct_scan.jpg"
4image = Image.open(requests.get(url, stream=True).raw)
5
6inputs = processor(text=prompt, images=image, return_tensors="pt").to(device, torch_dtype)
7
8generated_ids = model.generate(
9 input_ids=inputs["input_ids"],
10 pixel_values=inputs["pixel_values"],
11 max_new_tokens=1024,
12 do_sample=False,
13 num_beams=3
14)
15generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
16
17parsed_answer = processor.post_process_generation(generated_text, task="<DocVQA>", image_size=(image.width, image.height))
18
19print(parsed_answer)