|
1 | | -import argparse |
2 | | -import logging |
3 | | - |
4 | | -import torch |
| 1 | +import logging |
| 2 | +from pathlib import Path |
| 3 | +import torch |
5 | 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 |
6 | 9 |
|
7 | | -from monai.deploy.core import Application |
8 | 10 |
|
9 | 11 |
|
10 | 12 | class App(Application): |
11 | | - name = "Diffusion Image App" |
12 | | - description = "Simple application showing diffusion to generate Images" |
13 | | - |
14 | | - def compose(self): |
15 | | - model_id = "Nihirc/Prompt2MedImage" |
16 | | - device = "cuda" |
17 | | - parser = argparse.ArgumentParser() |
18 | | - parser.add_argument("--input_prompt", type=str, default="Generate a X-ray") |
19 | | - parser.add_argument("--output", type=str, default="./out.jpg") |
20 | | - args = parser.parse_args() |
21 | | - |
22 | | - input_prompt = args.input_prompt |
23 | | - output_path = args.output |
24 | | - print("Input Prompt: ", input_prompt) |
25 | | - pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) |
26 | | - pipe = pipe.to(device) |
27 | | - prompt = "Show me an X ray pevic fracture" |
28 | | - image = pipe(prompt).images[0] |
29 | | - image.save(output_path) |
| 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) |
30 | 31 |
|
31 | 32 |
|
32 | 33 | if __name__ == "__main__": |
33 | | - logging.info(f"Begin {__name__}") |
34 | | - App().run() |
35 | | - logging.info(f"End {__name__}") |
| 34 | + logging.info(f"Begin {__name__}") |
| 35 | + App().run() |
| 36 | + logging.info(f"End {__name__}") |
| 37 | + |
| 38 | + |
| 39 | + |
0 commit comments