dataautogpt3 commited on
Commit
3ae36c3
·
verified ·
1 Parent(s): ed57f8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -143
app.py CHANGED
@@ -6,182 +6,96 @@ import torch
6
 
7
  device = "cuda" if torch.cuda.is_available() else "cpu"
8
 
9
- if torch.cuda.is_available():
10
- torch.cuda.max_memory_allocated(device=device)
11
- # Load VAE component
12
- vae = AutoencoderKL.from_pretrained(
13
- "madebyollin/sdxl-vae-fp16-fix",
14
- torch_dtype=torch.float16
15
- )
16
-
17
- # Configure the pipeline
18
- pipe = StableDiffusionXLPipeline.from_pretrained(
19
- "dataautogpt3/ProteusV0.5",
20
- vae=vae,
21
- torch_dtype=torch.float16
22
- )
23
- pipe.scheduler = KDPM2AncestralDiscreteScheduler.from_config(pipe.scheduler.config)
24
- pipe.to(device)
25
- else:
26
- # Load VAE component
27
- vae = AutoencoderKL.from_pretrained(
28
- "madebyollin/sdxl-vae-fp16-fix",
29
- )
30
 
31
- # Configure the pipeline
32
- pipe = StableDiffusionXLPipeline.from_pretrained(
33
- "dataautogpt3/ProteusV0.5",
34
- vae=vae,
35
- )
36
- pipe.scheduler = KDPM2AncestralDiscreteScheduler.from_config(pipe.scheduler.config)
37
- pipe.to(device)
 
38
 
39
  MAX_SEED = np.iinfo(np.int32).max
40
  MAX_IMAGE_SIZE = 1024
41
 
42
- def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, clip_skip):
43
-
44
  if randomize_seed:
45
  seed = random.randint(0, MAX_SEED)
46
-
47
- generator = torch.Generator().manual_seed(seed)
48
 
49
  image = pipe(
50
- prompt = prompt,
51
- negative_prompt = negative_prompt,
52
- guidance_scale = guidance_scale,
53
- num_inference_steps = num_inference_steps,
54
- width = width,
55
- height = height,
56
- generator = generator,
57
- clip_skip = clip_skip
58
  ).images[0]
59
 
60
  return image
61
 
62
  examples = [
63
- "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
64
- "An astronaut riding a green horse",
65
- "A delicious ceviche cheesecake slice",
66
- "black fluffy gorgeous dangerous cat animal creature, large orange eyes, big fluffy ears, piercing gaze, full moon, dark ambiance, best quality, extremely detailed",
67
- "high quality pixel art, a pixel art silhouette of an anime space-themed girl in a space-punk steampunk style, lying in her bed by the window of a spaceship, smoking, with a rustic feel. The image should embody epic portraiture and double exposure, featuring an isolated landscape visible through the window. The colors should primarily be dynamic and action-packed, with a strong use of negative space. The entire artwork should be in pixel art style, emphasizing the characters shape and set against a white background. Silhouette"
68
  ]
69
 
70
- css="""
71
- #col-container {
72
- margin: 0 auto;
73
- max-width: 520px;
74
- }
75
  """
76
 
77
- if torch.cuda.is_available():
78
- power_device = "GPU"
79
- else:
80
- power_device = "CPU"
81
 
82
- with gr.Blocks(css=css) as demo:
 
 
 
 
 
 
 
 
 
 
83
 
84
  with gr.Column(elem_id="col-container"):
85
- gr.Markdown(f"""
86
- # ProteusV0.5 Demo
87
- Currently running on {power_device}.
88
-
89
- ProteusV0.5 is a state-of-the-art text-to-image model that leverages the power of Stable Diffusion to generate high-quality images from text prompts. This model has been fine-tuned on a large dataset of images and has been trained to understand a wide range of prompts and styles.
90
-
91
- With ProteusV0.5, you can generate images in a variety of styles, from realistic to abstract, and from simple to complex. The model is also capable of understanding and responding to complex prompts, making it a powerful tool for artists, designers, and anyone looking to generate high-quality images.
92
-
93
- To use this demo, simply enter a text prompt in the input field below, and the model will generate an image based on your prompt. You can also adjust the settings to control the quality and style of the generated image.
94
- """)
95
-
96
- with gr.Row():
97
-
98
- prompt = gr.Text(
99
- label="Prompt",
100
- show_label=False,
101
- max_lines=1,
102
- placeholder="Enter your prompt",
103
- container=False,
104
- )
105
-
106
- run_button = gr.Button("Run", scale=0)
107
-
108
- result = gr.Image(label="Result", show_label=False)
109
 
110
  with gr.Accordion("Advanced Settings", open=False):
111
-
112
- negative_prompt = gr.Text(
113
- label="Negative prompt",
114
- max_lines=1,
115
- placeholder="Enter a negative prompt",
116
- visible=False,
117
- )
118
-
119
- seed = gr.Slider(
120
- label="Seed",
121
- minimum=0,
122
- maximum=MAX_SEED,
123
- step=1,
124
- value=0,
125
- )
126
-
127
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
128
-
129
- with gr.Row():
130
-
131
- width = gr.Slider(
132
- label="Width",
133
- minimum=512,
134
- maximum=MAX_IMAGE_SIZE,
135
- step=32,
136
- value=1024,
137
- )
138
-
139
- height = gr.Slider(
140
- label="Height",
141
- minimum=512,
142
- maximum=MAX_IMAGE_SIZE,
143
- step=32,
144
- value=1024,
145
- )
146
-
147
- with gr.Row():
148
-
149
- guidance_scale = gr.Slider(
150
- label="Guidance scale",
151
- minimum=0.0,
152
- maximum=10.0,
153
- step=0.1,
154
- value=7.0,
155
- )
156
-
157
- num_inference_steps = gr.Slider(
158
- label="Number of inference steps",
159
- minimum=1,
160
- maximum=50,
161
- step=1,
162
- value=50,
163
- )
164
 
165
- clip_skip = gr.Slider(
166
- label="Clip skip",
167
- minimum=1,
168
- maximum=12,
169
- step=1,
170
- value=2,
171
- )
172
-
173
  gr.Examples(
174
  examples=examples,
175
- inputs=[prompt],
176
- outputs=[result],
177
  fn=infer,
178
  cache_examples=True
179
- )
180
 
181
  run_button.click(
182
  fn=infer,
183
  inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, clip_skip],
184
- outputs=[result]
185
  )
186
 
187
  demo.queue().launch()
 
6
 
7
  device = "cuda" if torch.cuda.is_available() else "cpu"
8
 
9
+ # Load VAE component
10
+ vae = AutoencoderKL.from_pretrained(
11
+ "madebyollin/sdxl-vae-fp16-fix",
12
+ torch_dtype=torch.float16 if device == "cuda" else torch.float32
13
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
+ # Configure the pipeline
16
+ pipe = StableDiffusionXLPipeline.from_pretrained(
17
+ "dataautogpt3/ProteusV0.5",
18
+ vae=vae,
19
+ torch_dtype=torch.float16 if device == "cuda" else torch.float32
20
+ )
21
+ pipe.scheduler = KDPM2AncestralDiscreteScheduler.from_config(pipe.scheduler.config)
22
+ pipe.to(device)
23
 
24
  MAX_SEED = np.iinfo(np.int32).max
25
  MAX_IMAGE_SIZE = 1024
26
 
27
+ def infer(prompt, negative_prompt="", seed=0, randomize_seed=True, width=1024, height=1024, guidance_scale=7.0, num_inference_steps=50, clip_skip=2):
 
28
  if randomize_seed:
29
  seed = random.randint(0, MAX_SEED)
30
+
31
+ generator = torch.Generator(device=device).manual_seed(seed)
32
 
33
  image = pipe(
34
+ prompt=prompt,
35
+ negative_prompt=negative_prompt,
36
+ guidance_scale=guidance_scale,
37
+ num_inference_steps=num_inference_steps,
38
+ width=width,
39
+ height=height,
40
+ generator=generator,
41
+ clip_skip=clip_skip
42
  ).images[0]
43
 
44
  return image
45
 
46
  examples = [
47
+ ["Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"],
48
+ ["An astronaut riding a green horse"],
49
+ ["A delicious ceviche cheesecake slice"],
50
+ ["black fluffy gorgeous dangerous cat animal creature, large orange eyes, big fluffy ears, piercing gaze, full moon, dark ambiance, best quality, extremely detailed"],
51
+ ["high quality pixel art, a pixel art silhouette of an anime space-themed girl in a space-punk steampunk style, lying in her bed by the window of a spaceship, smoking, with a rustic feel. The image should embody epic portraiture and double exposure, featuring an isolated landscape visible through the window. The colors should primarily be dynamic and action-packed, with a strong use of negative space. The entire artwork should be in pixel art style, emphasizing the characters shape and set against a white background. Silhouette"]
52
  ]
53
 
54
+ css = """
55
+ #col-container { max-width: 700px; margin: 0 auto; }
 
 
 
56
  """
57
 
58
+ demo = gr.Blocks(css=css)
 
 
 
59
 
60
+ with demo:
61
+ gr.Markdown(f"# ProteusV0.5 Demo")
62
+ gr.Markdown(f"Currently running on {'GPU' if torch.cuda.is_available() else 'CPU'}.")
63
+
64
+ gr.Markdown("""
65
+ ProteusV0.5 is a state-of-the-art text-to-image model that leverages the power of Stable Diffusion to generate high-quality images from text prompts. This model has been fine-tuned on a large dataset of images and has been trained to understand a wide range of prompts and styles.
66
+
67
+ With ProteusV0.5, you can generate images in a variety of styles, from realistic to abstract, and from simple to complex. The model is also capable of understanding and responding to complex prompts, making it a powerful tool for artists, designers, and anyone looking to generate high-quality images.
68
+
69
+ To use this demo, simply enter a text prompt in the input field below, and the model will generate an image based on your prompt. You can also adjust the settings to control the quality and style of the generated image.
70
+ """)
71
 
72
  with gr.Column(elem_id="col-container"):
73
+ prompt = gr.Text(label="Prompt", placeholder="Enter your prompt")
74
+ run_button = gr.Button("Generate Image")
75
+ result = gr.Image(label="Generated Image")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
  with gr.Accordion("Advanced Settings", open=False):
78
+ negative_prompt = gr.Text(label="Negative prompt", placeholder="Enter a negative prompt")
79
+ seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
81
+ width = gr.Slider(label="Width", minimum=512, maximum=MAX_IMAGE_SIZE, step=32, value=1024)
82
+ height = gr.Slider(label="Height", minimum=512, maximum=MAX_IMAGE_SIZE, step=32, value=1024)
83
+ guidance_scale = gr.Slider(label="Guidance scale", minimum=0.0, maximum=20.0, step=0.1, value=7.0)
84
+ num_inference_steps = gr.Slider(label="Number of inference steps", minimum=1, maximum=100, step=1, value=50)
85
+ clip_skip = gr.Slider(label="Clip skip", minimum=1, maximum=12, step=1, value=2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
 
 
 
 
 
 
 
 
87
  gr.Examples(
88
  examples=examples,
89
+ inputs=prompt,
90
+ outputs=result,
91
  fn=infer,
92
  cache_examples=True
93
+ )
94
 
95
  run_button.click(
96
  fn=infer,
97
  inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, clip_skip],
98
+ outputs=result
99
  )
100
 
101
  demo.queue().launch()