BiliSakura commited on
Commit
b4865e1
·
verified ·
1 Parent(s): 3dde604

Add files using upload-large-folder tool

Browse files
README.md CHANGED
@@ -9,6 +9,11 @@ tags:
9
  - histopathology
10
  - brca
11
  - custom-pipeline
 
 
 
 
 
12
  ---
13
 
14
  # BiliSakura/ZoomLDM-CDM-brca
@@ -50,7 +55,7 @@ from diffusers import DiffusionPipeline
50
 
51
  pipe = DiffusionPipeline.from_pretrained(
52
  "BiliSakura/ZoomLDM-CDM-brca",
53
- custom_pipeline="pipelin.py",
54
  trust_remote_code=True,
55
  ).to("cuda")
56
 
 
9
  - histopathology
10
  - brca
11
  - custom-pipeline
12
+ widget:
13
+ - src: demo_images/input.jpeg
14
+ prompt: Sample BRCA conditioning embedding (magnification class 0)
15
+ output:
16
+ url: demo_images/output.jpeg
17
  ---
18
 
19
  # BiliSakura/ZoomLDM-CDM-brca
 
55
 
56
  pipe = DiffusionPipeline.from_pretrained(
57
  "BiliSakura/ZoomLDM-CDM-brca",
58
+ custom_pipeline="pipeline.py",
59
  trust_remote_code=True,
60
  ).to("cuda")
61
 
demo_images/input.jpeg ADDED
demo_images/output.jpeg ADDED
run_demo_inference.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Run ZoomLDM-CDM-brca demo inference and save visualization to demo_images/."""
3
+ from pathlib import Path
4
+
5
+ import numpy as np
6
+ import torch
7
+ from diffusers import DiffusionPipeline
8
+ from PIL import Image, ImageDraw
9
+
10
+
11
+ def main() -> None:
12
+ repo = Path(__file__).resolve().parent
13
+ demo_dir = repo / "demo_images"
14
+ demo_dir.mkdir(exist_ok=True)
15
+
16
+ pipe = DiffusionPipeline.from_pretrained(
17
+ str(repo),
18
+ custom_pipeline=str(repo / "pipeline.py"),
19
+ trust_remote_code=True,
20
+ local_files_only=True,
21
+ ).to("cuda")
22
+
23
+ magnification = torch.tensor([0], device="cuda")
24
+ out = pipe(
25
+ batch_size=1,
26
+ magnification=magnification,
27
+ num_inference_steps=50,
28
+ guidance_scale=1.0,
29
+ )
30
+
31
+ # out.samples: (1, 512, 65) -> visualize first sample as a heatmap-like image
32
+ sample = out.samples[0].detach().float().cpu().numpy()
33
+ sample = (sample - sample.min()) / (sample.max() - sample.min() + 1e-8)
34
+ sample_u8 = (sample * 255).astype(np.uint8) # (512, 65)
35
+ img = Image.fromarray(sample_u8, mode="L").resize((520, 512), Image.Resampling.NEAREST).convert("RGB")
36
+ img.save(demo_dir / "output.jpeg")
37
+
38
+ # Simple input card to make widget context explicit
39
+ card = Image.new("RGB", (520, 512), color=(245, 245, 245))
40
+ draw = ImageDraw.Draw(card)
41
+ draw.text((24, 24), "ZoomLDM-CDM-brca", fill=(20, 20, 20))
42
+ draw.text((24, 64), "Input: magnification class = 0", fill=(40, 40, 40))
43
+ draw.text((24, 100), "Output: sampled conditioning tensor visualization", fill=(40, 40, 40))
44
+ card.save(demo_dir / "input.jpeg")
45
+
46
+ print(f"Saved {demo_dir / 'input.jpeg'}")
47
+ print(f"Saved {demo_dir / 'output.jpeg'}")
48
+
49
+
50
+ if __name__ == "__main__":
51
+ main()