File tree Expand file tree Collapse file tree 5 files changed +56
-0
lines changed
examples/apps/hugging_face_integration_app Expand file tree Collapse file tree 5 files changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ FROM nvcr.io/nvidia/clara-holoscan/holoscan:v2.1.0-dgpu
2
+ RUN pip install --upgrade pip
3
+ RUN pip install monai-deploy-app-sdk
4
+ RUN pip install transformers
5
+ RUN pip install hub
6
+ RUN pip install diffusers
7
+ RUN pip install torch
8
+ RUN pip install pydicom
9
+ RUN pip install accelerate
Original file line number Diff line number Diff line change
1
+ IMAGE=vikash112/monai-hugging:0.1.0
2
+ docker build -t $IMAGE .
3
+
4
+ monai_dir=/raid/Vikash/Tools/HUGGINGFACE/med_image_generation
5
+
6
+ NV_GPU=1 nvidia-docker run -it --rm --shm-size=4g --ulimit memlock=-1 --ulimit stack=67108864 -v $monai_dir :/workspace/app/test $IMAGE /bin/bash
Original file line number Diff line number Diff line change
1
+ import logging
2
+ from pathlib import Path
3
+ import torch
4
+ from diffusers import StableDiffusionPipeline
5
+ from monai .deploy .core import AppContext , Application
6
+ from PIL import Image
7
+ import numpy as np
8
+ import argparse
9
+
10
+
11
+
12
+ class App (Application ):
13
+ name = "Diffusion Image App"
14
+ description = "Simple application showing diffusion to generate Images"
15
+ def compose (self ):
16
+ model_id = "Nihirc/Prompt2MedImage"
17
+ device = "cuda"
18
+ parser = argparse .ArgumentParser ()
19
+ parser .add_argument ("--input_prompt" , type = str , default = "Generate a X-ray" )
20
+ parser .add_argument ("--output" , type = str , default = "./out.jpg" )
21
+ args = parser .parse_args ()
22
+
23
+ input_prompt = args .input_prompt
24
+ output_path = args .output
25
+ print ("Input Prompt: " , input_prompt )
26
+ pipe = StableDiffusionPipeline .from_pretrained (model_id , torch_dtype = torch .float16 )
27
+ pipe = pipe .to (device )
28
+ prompt = "Show me an X ray pevic fracture"
29
+ image = pipe (prompt ).images [0 ]
30
+ image .save (output_path )
31
+
32
+
33
+ if __name__ == "__main__" :
34
+ logging .info (f"Begin { __name__ } " )
35
+ App ().run ()
36
+ logging .info (f"End { __name__ } " )
37
+
38
+
39
+
Original file line number Diff line number Diff line change
1
+
2
+ python app.py --input_prompt " The patient had residual paralysis of the hand after poliomyelitis. It was necessary to stabilize the thumb with reference to the index finger. This was accomplished by placing a graft from the bone bank between the first and second metacarpals. The roentgenogram shows the complete healing of the graft one year later." --output out.jpg
You can’t perform that action at this time.
0 commit comments