BTX24 commited on
Commit
f580460
·
verified ·
1 Parent(s): 204a35d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +31 -4
README.md CHANGED
@@ -18,11 +18,38 @@ It has been trained using [TRL](https://github.com/huggingface/trl).
18
 
19
  ```python
20
  from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- question = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"
23
- generator = pipeline("text-generation", model="BTX24/medgemma-4b-it-sft-lora-stroke", device="cuda")
24
- output = generator([{"role": "user", "content": question}], max_new_tokens=128, return_full_text=False)[0]
25
- print(output["generated_text"])
26
  ```
27
 
28
  ## Training procedure
 
18
 
19
  ```python
20
  from transformers import pipeline
21
+ from PIL import Image
22
+ import requests
23
+ import torch
24
+
25
+ pipe = pipeline(
26
+ "image-text-to-text",
27
+ model="BTX24/medgemma-4b-it-sft-lora-stroke",
28
+ torch_dtype=torch.bfloat16,
29
+ device="cuda",
30
+ )
31
+
32
+ # Image attribution: Stillwaterising, CC0, via Wikimedia Commons
33
+ image_url = "https://storage.googleapis.com/kagglesdsdata/datasets/6652053/10729545/%C4%B0NME%20VER%C4%B0%20SET%C4%B0/Kanama/PNG/10033.png?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=gcp-kaggle-com%40kaggle-161607.iam.gserviceaccount.com%2F20250605%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20250605T135753Z&X-Goog-Expires=259200&X-Goog-SignedHeaders=host&X-Goog-Signature=2e6408958b200e1b573c9f62f7b97a9c8cbdc8fc49c84e112a8c148226ec813c74c2da88404689d1563efac8f7759f86b14a579f3a15126b48fb74a6e3776d9fdf2c14471f6bca7b8a6c92f97af3678fb132f968e0eb318a32eef45794e3da8f1227b37aab36c3040cbb9f59c20116b498ce36c1ac19a75c5678dbbbb85bc00c91435f68935be48b50382750d3f5cdd3bd2dca06bce90b7b3f76d54ba454d7cf54ebd94b540e9d67127a7277e856a27d725dbed4ab9482b6b9c5e5ba6422182a5afbedf7b5ed2a3a4670b181b9b08fc538dce2743e3d8bfe39f4cb5bc9d78fb3205697b325ea8c37a70bd5350afcc9b41aee0a859462cf26b476db206e073513"
34
+ image = Image.open(requests.get(image_url, headers={"User-Agent": "example"}, stream=True).raw)
35
+
36
+ messages = [
37
+ {
38
+ "role": "system",
39
+ "content": [{"type": "text", "text": "You are an expert radiologist."}]
40
+ },
41
+ {
42
+ "role": "user",
43
+ "content": [
44
+ {"type": "text", "text": "Describe this X-ray"}
45
+ {"type": "image", "image": image},
46
+ ]
47
+ }
48
+ ]
49
+
50
+ output = pipe(text=messages, max_new_tokens=200)
51
+ print(output[0]["generated_text"][-1]["content"])
52
 
 
 
 
 
53
  ```
54
 
55
  ## Training procedure