Skip to content

Commit caf9790

Browse files
vikashgVikash Gupta
and
Vikash Gupta
authored
Added a sample integration for LLM models in huggingface (#494)
* Added a sample integration for LLM models in huggingface Signed-off-by: Vikash Gupta <gupta.vikash@mayo.edu> * Fixed minor issue Signed-off-by: Vikash Gupta <gupta.vikash@mayo.edu> --------- Signed-off-by: Vikash Gupta <gupta.vikash@mayo.edu> Co-authored-by: Vikash Gupta <gupta.vikash@mayo.edu>
1 parent 07fd50e commit caf9790

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
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

0 commit comments

Comments
 (0)