diff --git a/examples/apps/hugging_face_integration_app/Dockerfile b/examples/apps/hugging_face_integration_app/Dockerfile new file mode 100644 index 00000000..0661a059 --- /dev/null +++ b/examples/apps/hugging_face_integration_app/Dockerfile @@ -0,0 +1,9 @@ +FROM nvcr.io/nvidia/clara-holoscan/holoscan:v2.1.0-dgpu +RUN pip install --upgrade pip +RUN pip install monai-deploy-app-sdk +RUN pip install transformers +RUN pip install hub +RUN pip install diffusers +RUN pip install torch +RUN pip install pydicom +RUN pip install accelerate diff --git a/examples/apps/hugging_face_integration_app/debug.sh b/examples/apps/hugging_face_integration_app/debug.sh new file mode 100644 index 00000000..0867c177 --- /dev/null +++ b/examples/apps/hugging_face_integration_app/debug.sh @@ -0,0 +1,6 @@ +IMAGE=vikash112/monai-hugging:0.1.0 +docker build -t $IMAGE . + +monai_dir=/raid/Vikash/Tools/HUGGINGFACE/med_image_generation + +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 diff --git a/examples/apps/hugging_face_integration_app/med_image_generation/app.py b/examples/apps/hugging_face_integration_app/med_image_generation/app.py new file mode 100644 index 00000000..8751d03c --- /dev/null +++ b/examples/apps/hugging_face_integration_app/med_image_generation/app.py @@ -0,0 +1,40 @@ +import logging +from pathlib import Path +import torch +from diffusers import StableDiffusionPipeline +from monai.deploy.core import AppContext, Application +from PIL import Image +import numpy as np +import argparse + + + +class App(Application): + name = "Diffusion Image App" + description = "Simple application showing diffusion to generate Images" + def compose(self): + model_id = "Nihirc/Prompt2MedImage" + device = "cuda" + parser = argparse.ArgumentParser() + parser.add_argument("--input_prompt", type=str, default="Generate a X-ray") + parser.add_argument("--output", type=str, default="./out.jpg") + args = parser.parse_args() + + input_prompt = args.input_prompt + output_path = args.output + print("Input Prompt: ", input_prompt) + pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) + pipe = pipe.to(device) + #prompt = "Show me an X ray of ankle with a fractured toe" + prompt = "Show me an X ray pevic fracture" + image = pipe(prompt).images[0] + image.save(output_path) + + +if __name__ == "__main__": + logging.info(f"Begin {__name__}") + App().run() + logging.info(f"End {__name__}") + + + diff --git a/examples/apps/hugging_face_integration_app/med_image_generation/out.jpg b/examples/apps/hugging_face_integration_app/med_image_generation/out.jpg new file mode 100644 index 00000000..2431118b Binary files /dev/null and b/examples/apps/hugging_face_integration_app/med_image_generation/out.jpg differ diff --git a/examples/apps/hugging_face_integration_app/med_image_generation/run.sh b/examples/apps/hugging_face_integration_app/med_image_generation/run.sh new file mode 100644 index 00000000..02472ee7 --- /dev/null +++ b/examples/apps/hugging_face_integration_app/med_image_generation/run.sh @@ -0,0 +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