Cylumn commited on
Commit
21bc0bf
·
verified ·
1 Parent(s): 1864860

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -14
app.py CHANGED
@@ -7,22 +7,19 @@ from diffusers import DiffusionPipeline
7
  import torch
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
- model_repo_id = "stabilityai/sdxl-turbo" # Replace to the model you would like to use
11
 
12
  if torch.cuda.is_available():
13
- torch_dtype = torch.float16
14
  else:
15
  torch_dtype = torch.float32
16
 
17
- pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
18
- pipe = pipe.to(device)
19
-
20
  MAX_SEED = np.iinfo(np.int32).max
21
  MAX_IMAGE_SIZE = 1024
22
 
23
 
24
  # @spaces.GPU #[uncomment to use ZeroGPU]
25
  def infer(
 
26
  prompt,
27
  negative_prompt,
28
  seed,
@@ -38,6 +35,9 @@ def infer(
38
 
39
  generator = torch.Generator().manual_seed(seed)
40
 
 
 
 
41
  image = pipe(
42
  prompt=prompt,
43
  negative_prompt=negative_prompt,
@@ -52,9 +52,9 @@ def infer(
52
 
53
 
54
  examples = [
55
- "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
56
- "An astronaut riding a green horse",
57
- "A delicious ceviche cheesecake slice",
58
  ]
59
 
60
  css = """
@@ -66,7 +66,14 @@ css = """
66
 
67
  with gr.Blocks(css=css) as demo:
68
  with gr.Column(elem_id="col-container"):
69
- gr.Markdown(" # Text-to-Image Gradio Template")
 
 
 
 
 
 
 
70
 
71
  with gr.Row():
72
  prompt = gr.Text(
@@ -102,7 +109,7 @@ with gr.Blocks(css=css) as demo:
102
  with gr.Row():
103
  width = gr.Slider(
104
  label="Width",
105
- minimum=256,
106
  maximum=MAX_IMAGE_SIZE,
107
  step=32,
108
  value=1024, # Replace with defaults that work for your model
@@ -110,7 +117,7 @@ with gr.Blocks(css=css) as demo:
110
 
111
  height = gr.Slider(
112
  label="Height",
113
- minimum=256,
114
  maximum=MAX_IMAGE_SIZE,
115
  step=32,
116
  value=1024, # Replace with defaults that work for your model
@@ -119,10 +126,10 @@ with gr.Blocks(css=css) as demo:
119
  with gr.Row():
120
  guidance_scale = gr.Slider(
121
  label="Guidance scale",
122
- minimum=0.0,
123
  maximum=10.0,
124
  step=0.1,
125
- value=0.0, # Replace with defaults that work for your model
126
  )
127
 
128
  num_inference_steps = gr.Slider(
@@ -130,7 +137,7 @@ with gr.Blocks(css=css) as demo:
130
  minimum=1,
131
  maximum=50,
132
  step=1,
133
- value=2, # Replace with defaults that work for your model
134
  )
135
 
136
  gr.Examples(examples=examples, inputs=[prompt])
@@ -138,6 +145,7 @@ with gr.Blocks(css=css) as demo:
138
  triggers=[run_button.click, prompt.submit],
139
  fn=infer,
140
  inputs=[
 
141
  prompt,
142
  negative_prompt,
143
  seed,
 
7
  import torch
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
10
 
11
  if torch.cuda.is_available():
12
+ torch_dtype = torch.bfloat16
13
  else:
14
  torch_dtype = torch.float32
15
 
 
 
 
16
  MAX_SEED = np.iinfo(np.int32).max
17
  MAX_IMAGE_SIZE = 1024
18
 
19
 
20
  # @spaces.GPU #[uncomment to use ZeroGPU]
21
  def infer(
22
+ model_repo_id,
23
  prompt,
24
  negative_prompt,
25
  seed,
 
35
 
36
  generator = torch.Generator().manual_seed(seed)
37
 
38
+
39
+ pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
40
+ pipe = pipe.to(device)
41
  image = pipe(
42
  prompt=prompt,
43
  negative_prompt=negative_prompt,
 
52
 
53
 
54
  examples = [
55
+ "mimic: PA view, FINAL REPORT\n PA AND LATERAL CHEST OF ___\n \n COMPARISON: ___ radiograph.\n \n FINDINGS: Cardiac silhouette is upper limits of normal in size and\n accompanied by pulmonary vascular congestion and a basilar predominant\n interstitial abnormality which most likely represents interstitial edema. \n Small bilateral pleural effusions are present, left greater than right, with\n interval decrease in size since the prior radiograph. There is also improving\n aeration in the left retrocardiac region, likely resolving atelectasis.",
56
+ "mimic: AP view, small left-sided pleural effusion, discrete density overlying the postero-lateral rib, supraclavicular catheter at the cavoatrial junction, new opacity within the left lower lobe and lingula",
57
+ "mimic: AP view, FINAL REPORT\n EXAMINATION: CHEST (PORTABLE AP)\n \n INDICATION: ___ year old woman with ?TIA // r/o acute CP process r/o\n acute CP process\n \n IMPRESSION: \n \n In comparison with the study of ___, there again are low lung\n volumes with elevation of the right hemidiaphragmatic contour. Cardiac\n silhouette is at the upper limits of normal or mildly enlarged. No evidence of\n acute pneumonia or vascular congestion.\n \n Right IJ catheter extends to the mid to lower portion of the SVC.",
58
  ]
59
 
60
  css = """
 
66
 
67
  with gr.Blocks(css=css) as demo:
68
  with gr.Column(elem_id="col-container"):
69
+ gr.Markdown(" # SD Demo")
70
+
71
+ with gr.Row():
72
+ model_repo_id = gr.Dropdown(
73
+ choices=['Cylumn/sd2-findings', 'Cylumn/sd2-report', 'Cylumn/sd3-report'],
74
+ label="Select Model",
75
+ value='Cylumn/sd3-report'
76
+ )
77
 
78
  with gr.Row():
79
  prompt = gr.Text(
 
109
  with gr.Row():
110
  width = gr.Slider(
111
  label="Width",
112
+ minimum=512,
113
  maximum=MAX_IMAGE_SIZE,
114
  step=32,
115
  value=1024, # Replace with defaults that work for your model
 
117
 
118
  height = gr.Slider(
119
  label="Height",
120
+ minimum=512,
121
  maximum=MAX_IMAGE_SIZE,
122
  step=32,
123
  value=1024, # Replace with defaults that work for your model
 
126
  with gr.Row():
127
  guidance_scale = gr.Slider(
128
  label="Guidance scale",
129
+ minimum=7.5,
130
  maximum=10.0,
131
  step=0.1,
132
+ value=7.5, # Replace with defaults that work for your model
133
  )
134
 
135
  num_inference_steps = gr.Slider(
 
137
  minimum=1,
138
  maximum=50,
139
  step=1,
140
+ value=35, # Replace with defaults that work for your model
141
  )
142
 
143
  gr.Examples(examples=examples, inputs=[prompt])
 
145
  triggers=[run_button.click, prompt.submit],
146
  fn=infer,
147
  inputs=[
148
+ model_repo_id,
149
  prompt,
150
  negative_prompt,
151
  seed,