TheVeshup commited on
Commit
3924b43
·
verified ·
1 Parent(s): f0d1184

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +171 -87
app.py CHANGED
@@ -33,11 +33,13 @@ def infer(
33
  num_inference_steps,
34
  progress=gr.Progress(track_tqdm=True),
35
  ):
 
36
  if randomize_seed:
37
  seed = random.randint(0, MAX_SEED)
38
 
39
  generator = torch.Generator().manual_seed(seed)
40
 
 
41
  image = pipe(
42
  prompt=prompt,
43
  negative_prompt=negative_prompt,
@@ -58,88 +60,170 @@ examples = [
58
  ]
59
 
60
  css = """
61
- /* General Styles */
62
- #col-container {
63
- margin: 0 auto;
64
- max-width: 640px;
65
- font-family: 'Arial', sans-serif;
66
- color: #333;
67
- background-color: #f0f4f8; /* Light gray background for better contrast */
68
- border-radius: 15px;
69
- padding: 20px;
70
- }
71
-
72
- #header {
73
- text-align: center;
74
- color: #1f5f99; /* Veshup Blue */
75
- }
76
-
77
- #title {
78
- font-size: 36px;
79
- font-weight: bold;
80
- margin-bottom: 10px;
81
- }
82
-
83
- #subtitle {
84
- font-size: 18px;
85
- color: #555;
86
- margin-bottom: 30px;
87
- }
88
-
89
- .gradio-button {
90
- background-color: #1f5f99;
91
- color: white;
92
- font-weight: bold;
93
- border-radius: 8px;
94
- }
95
-
96
- .gradio-button:hover {
97
- background-color: #155b89;
98
- }
99
-
100
- .gradio-slider {
101
- width: 100%;
102
- }
103
-
104
- .gradio-checkbox label {
105
- font-weight: normal;
106
- }
107
-
108
- .gradio-markdown {
109
- font-size: 16px;
110
- line-height: 1.6;
111
- }
112
-
113
- /* Dark Mode adjustments for browser default theme */
114
- @media (prefers-color-scheme: dark) {
115
- #col-container {
116
- background-color: #2e2e2e; /* Dark background for dark mode */
117
- color: #e0e0e0; /* Light text for dark mode */
118
- }
119
-
120
- #header {
121
- color: #a5c4f6; /* Lighter blue for dark mode */
122
- }
123
-
124
- .gradio-button {
125
- background-color: #4f89b0;
126
- }
127
-
128
- .gradio-button:hover {
129
- background-color: #3a6a8b;
130
- }
131
-
132
- .gradio-slider,
133
- .gradio-checkbox {
134
- background-color: #444; /* Darker elements in dark mode */
135
- }
136
-
137
- .gradio-markdown {
138
- color: #d1d1d1; /* Lighter text for markdown */
139
- }
140
- }
141
  """
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  with gr.Blocks(css=css) as demo:
144
  with gr.Column(elem_id="col-container"):
145
  gr.Markdown("<div id='header'><h1 id='title'>Veginator: Veshup's Image Generation AI</h1><p id='subtitle'>Create stunning images with just a prompt. Powered by cutting-edge AI technology.</p></div>")
@@ -181,7 +265,7 @@ with gr.Blocks(css=css) as demo:
181
  minimum=256,
182
  maximum=MAX_IMAGE_SIZE,
183
  step=32,
184
- value=1024, # Replace with defaults that work for your model
185
  )
186
 
187
  height = gr.Slider(
@@ -189,24 +273,24 @@ with gr.Blocks(css=css) as demo:
189
  minimum=256,
190
  maximum=MAX_IMAGE_SIZE,
191
  step=32,
192
- value=1024, # Replace with defaults that work for your model
193
  )
194
 
195
  with gr.Row():
196
  guidance_scale = gr.Slider(
197
  label="Guidance Scale",
198
  minimum=0.0,
199
- maximum=10.0,
200
  step=0.1,
201
- value=0.0, # Replace with defaults that work for your model
202
  )
203
 
204
  num_inference_steps = gr.Slider(
205
  label="Number of Inference Steps",
206
  minimum=1,
207
- maximum=50,
208
  step=1,
209
- value=2, # Replace with defaults that work for your model
210
  )
211
 
212
  gr.Examples(examples=examples, inputs=[prompt])
@@ -227,4 +311,4 @@ with gr.Blocks(css=css) as demo:
227
  )
228
 
229
  if __name__ == "__main__":
230
- demo.launch()
 
33
  num_inference_steps,
34
  progress=gr.Progress(track_tqdm=True),
35
  ):
36
+ # Seed Handling
37
  if randomize_seed:
38
  seed = random.randint(0, MAX_SEED)
39
 
40
  generator = torch.Generator().manual_seed(seed)
41
 
42
+ # Generate Image
43
  image = pipe(
44
  prompt=prompt,
45
  negative_prompt=negative_prompt,
 
60
  ]
61
 
62
  css = """
63
+ /* CSS Styling (remains unchanged from earlier examples) */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  """
65
 
66
+ # Higher Defaults for Advanced Settings
67
+ DEFAULT_STEPS = 50
68
+ DEFAULT_GUIDANCE = 7.5
69
+
70
+ with gr.Blocks(css=css) as demo:
71
+ with gr.Column(elem_id="col-container"):
72
+ gr.Markdown("<div id='header'><h1 id='title'>Veginator: Veshup's Image Generation AI</h1><p id='subtitle'>Create stunning images with just a prompt. Powered by cutting-edge AI technology.</p></div>")
73
+
74
+ with gr.Row():
75
+ prompt = gr.Text(
76
+ label="Your Creative Prompt",
77
+ show_label=False,
78
+ max_lines=1,
79
+ placeholder="Enter your prompt here...",
80
+ container=False,
81
+ )
82
+
83
+ run_button = gr.Button("Generate Image", scale=0, variant="primary", elem_classes="gradio-button")
84
+
85
+ result = gr.Image(label="Generated Image", show_label=False)
86
+
87
+ with gr.Accordion("Advanced Settings", open=False):
88
+ negative_prompt = gr.Text(
89
+ label="Negative Prompt",
90
+ max_lines=1,
91
+ placeholder="Enter a negative prompt if needed",
92
+ visible=False,
93
+ )
94
+
95
+ seed = gr.Slider(
96
+ label="Seed",
97
+ minimum=0,
98
+ maximum=MAX_SEED,
99
+ step=1,
100
+ value=0,
101
+ )
102
+
103
+ randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
104
+
105
+ with gr.Row():
106
+ width = gr.Slider(
107
+ label="Width",
108
+ minimum=256,
109
+ maximum=MAX_IMAGE_SIZE,
110
+ step=32,
111
+ value=768, # Higher default resolution
112
+ )
113
+
114
+ height = gr.Slider(
115
+ label="Height",
116
+ minimum=256,
117
+ maximum=MAX_IMAGE_SIZE,
118
+ step=32,
119
+ value=768, # Higher default resolution
120
+ )
121
+
122
+ with gr.Row():
123
+ guidance_scale = gr.Slider(
124
+ label="Guidance Scale",
125
+ minimum=0.0,
126
+ maximum=15.0,
127
+ step=0.1,
128
+ value=DEFAULT_GUIDANCE, # Higher guidance by default
129
+ )
130
+
131
+ num_inference_steps = gr.Slider(
132
+ label="Number of Inference Steps",
133
+ minimum=1,
134
+ maximum=150, # Increased maximum steps
135
+ step=1,
136
+ value=DEFAULT_STEPS, # Higher inference steps for quality
137
+ )
138
+
139
+ gr.Examples(examples=examples, inputs=[prompt])
140
+ gr.on(
141
+ triggers=[run_button.click, prompt.submit],
142
+ fn=infer,
143
+ inputs=[
144
+ prompt,
145
+ negative_prompt,
146
+ seed,
147
+ randomize_seed,
148
+ width,
149
+ height,
150
+ guidance_scale,
151
+ num_inference_steps,
152
+ ],
153
+ outputs=[result, seed],
154
+ )
155
+
156
+ if __name__ == "__main__":
157
+ demo.launch()
158
+ import gradio as gr
159
+ import numpy as np
160
+ import random
161
+
162
+ import spaces #[uncomment to use ZeroGPU]
163
+ from diffusers import DiffusionPipeline
164
+ import torch
165
+
166
+ device = "cuda" if torch.cuda.is_available() else "cpu"
167
+ model_repo_id = "stabilityai/sdxl-turbo" # Replace to the model you would like to use
168
+
169
+ if torch.cuda.is_available():
170
+ torch_dtype = torch.float16
171
+ else:
172
+ torch_dtype = torch.float32
173
+
174
+ pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
175
+ pipe = pipe.to(device)
176
+
177
+ MAX_SEED = np.iinfo(np.int32).max
178
+ MAX_IMAGE_SIZE = 1024
179
+
180
+
181
+ @spaces.GPU #[uncomment to use ZeroGPU]
182
+ def infer(
183
+ prompt,
184
+ negative_prompt,
185
+ seed,
186
+ randomize_seed,
187
+ width,
188
+ height,
189
+ guidance_scale,
190
+ num_inference_steps,
191
+ progress=gr.Progress(track_tqdm=True),
192
+ ):
193
+ # Seed Handling
194
+ if randomize_seed:
195
+ seed = random.randint(0, MAX_SEED)
196
+
197
+ generator = torch.Generator().manual_seed(seed)
198
+
199
+ # Generate Image
200
+ image = pipe(
201
+ prompt=prompt,
202
+ negative_prompt=negative_prompt,
203
+ guidance_scale=guidance_scale,
204
+ num_inference_steps=num_inference_steps,
205
+ width=width,
206
+ height=height,
207
+ generator=generator,
208
+ ).images[0]
209
+
210
+ return image, seed
211
+
212
+
213
+ examples = [
214
+ "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
215
+ "An astronaut riding a green horse",
216
+ "A delicious ceviche cheesecake slice",
217
+ ]
218
+
219
+ css = """
220
+ /* CSS Styling (remains unchanged from earlier examples) */
221
+ """
222
+
223
+ # Higher Defaults for Advanced Settings
224
+ DEFAULT_STEPS = 50
225
+ DEFAULT_GUIDANCE = 7.5
226
+
227
  with gr.Blocks(css=css) as demo:
228
  with gr.Column(elem_id="col-container"):
229
  gr.Markdown("<div id='header'><h1 id='title'>Veginator: Veshup's Image Generation AI</h1><p id='subtitle'>Create stunning images with just a prompt. Powered by cutting-edge AI technology.</p></div>")
 
265
  minimum=256,
266
  maximum=MAX_IMAGE_SIZE,
267
  step=32,
268
+ value=768, # Higher default resolution
269
  )
270
 
271
  height = gr.Slider(
 
273
  minimum=256,
274
  maximum=MAX_IMAGE_SIZE,
275
  step=32,
276
+ value=768, # Higher default resolution
277
  )
278
 
279
  with gr.Row():
280
  guidance_scale = gr.Slider(
281
  label="Guidance Scale",
282
  minimum=0.0,
283
+ maximum=15.0,
284
  step=0.1,
285
+ value=DEFAULT_GUIDANCE, # Higher guidance by default
286
  )
287
 
288
  num_inference_steps = gr.Slider(
289
  label="Number of Inference Steps",
290
  minimum=1,
291
+ maximum=150, # Increased maximum steps
292
  step=1,
293
+ value=DEFAULT_STEPS, # Higher inference steps for quality
294
  )
295
 
296
  gr.Examples(examples=examples, inputs=[prompt])
 
311
  )
312
 
313
  if __name__ == "__main__":
314
+ demo.launch()