sagar007 commited on
Commit
11ba365
·
verified ·
1 Parent(s): 6538990

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +99 -50
app.py CHANGED
@@ -11,80 +11,120 @@ from diffusers import AutoencoderKL, LMSDiscreteScheduler, UNet2DConditionModel,
11
  HTML_TEMPLATE = """
12
  <style>
13
  body {
14
- background: linear-gradient(135deg, #f5f7fa, #c3cfe2);
 
 
15
  }
16
  #app-header {
17
  text-align: center;
18
- background: rgba(255, 255, 255, 0.8);
19
- padding: 20px;
20
- border-radius: 10px;
21
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
22
  position: relative;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  }
24
  #app-header h1 {
25
- color: #4CAF50;
26
- font-size: 2em;
27
- margin-bottom: 10px;
 
 
 
 
 
 
 
 
 
 
 
 
28
  }
29
  .concept {
30
  position: relative;
31
- transition: transform 0.3s;
 
 
 
 
32
  }
33
  .concept:hover {
34
- transform: scale(1.1);
 
35
  }
36
  .concept img {
37
- width: 100px;
38
- border-radius: 10px;
39
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
 
40
  }
41
  .concept-description {
42
- position: absolute;
43
- bottom: -30px;
44
- left: 50%;
45
- transform: translateX(-50%);
46
- background-color: #4CAF50;
47
  color: white;
48
- padding: 5px 10px;
49
- border-radius: 5px;
50
- opacity: 0;
51
- transition: opacity 0.3s;
52
- }
53
- .concept:hover .concept-description {
54
- opacity: 1;
55
  }
56
  .artifact {
57
  position: absolute;
58
- background: rgba(76, 175, 80, 0.1);
59
  border-radius: 50%;
 
60
  }
61
  .artifact.large {
62
- width: 300px;
63
- height: 300px;
64
- top: -50px;
65
- left: -150px;
 
66
  }
67
  .artifact.medium {
68
- width: 200px;
69
- height: 200px;
70
- bottom: -50px;
71
- right: -100px;
 
72
  }
73
  .artifact.small {
74
- width: 100px;
75
- height: 100px;
76
  top: 50%;
77
  left: 50%;
78
  transform: translate(-50%, -50%);
 
 
 
 
 
 
 
 
 
79
  }
80
  </style>
81
  <div id="app-header">
82
  <div class="artifact large"></div>
83
  <div class="artifact medium"></div>
84
  <div class="artifact small"></div>
85
- <h1>Generative Art with Textual Inversion and Guidance</h1>
86
- <p>Generate unique art using different styles and guidance methods.</p>
87
- <div style="display: flex; justify-content: center; gap: 20px; margin-top: 20px;">
88
  <div class="concept">
89
  <img src="https://example.com/illustration-style.jpg" alt="Illustration Style">
90
  <div class="concept-description">Illustration Style</div>
@@ -93,7 +133,14 @@ HTML_TEMPLATE = """
93
  <img src="https://example.com/line-art.jpg" alt="Line Art">
94
  <div class="concept-description">Line Art</div>
95
  </div>
96
- <!-- Add more concepts here for each style in your style_token_dict -->
 
 
 
 
 
 
 
97
  </div>
98
  </div>
99
  """
@@ -198,37 +245,39 @@ title = "Generative Art with Textual Inversion and Guidance"
198
  description = "Create unique artworks using Stable Diffusion with various styles and guidance methods."
199
 
200
  with gr.Blocks(css=HTML_TEMPLATE) as demo:
201
- gr.HTML(HTML_TEMPLATE) # This adds the styled header to your app
202
  with gr.Row():
203
- text = gr.Textbox(label="Prompt", placeholder="Enter your creative prompt here...")
204
  style = gr.Dropdown(label="Style", choices=list(style_token_dict.keys()), value="Illustration Style")
205
  with gr.Row():
206
- inference_step = gr.Slider(1, 50, 10, step=1, label="Inference steps")
207
  guidance_scale = gr.Slider(1, 10, 7.5, step=0.1, label="Guidance scale")
208
  seed = gr.Slider(0, 10000, 42, step=1, label="Seed")
209
  with gr.Row():
210
  guidance_method = gr.Dropdown(label="Guidance method", choices=['Grayscale', 'Bright', 'Contrast', 'Symmetry', 'Saturation'], value="Grayscale")
211
  loss_scale = gr.Slider(100, 10000, 200, step=100, label="Loss scale")
212
  with gr.Row():
213
- generate_button = gr.Button("Generate Art")
 
 
214
  with gr.Row():
215
- output_image = gr.Image(width=512, height=512, label="Generated art")
216
- output_image_guided = gr.Image(width=512, height=512, label="Generated art with guidance")
217
 
218
  generate_button.click(
219
  inference,
220
- inputs=[text, style, inference_step, guidance_scale, seed, guidance_method, loss_scale],
221
  outputs=[output_image, output_image_guided]
222
  )
223
 
224
  gr.Examples(
225
  examples=[
226
- ["A majestic castle on a floating island", 'Illustration Style', 10, 7.5, 42, 'Grayscale', 200]
227
  ],
228
- inputs=[text, style, inference_step, guidance_scale, seed, guidance_method, loss_scale],
229
  outputs=[output_image, output_image_guided],
230
  fn=inference,
231
  cache_examples=True,
232
  )
233
 
234
- demo.launch()
 
11
  HTML_TEMPLATE = """
12
  <style>
13
  body {
14
+ background: linear-gradient(135deg, #6e48aa, #9d50bb, #f4d03f);
15
+ font-family: 'Arial', sans-serif;
16
+ color: #333;
17
  }
18
  #app-header {
19
  text-align: center;
20
+ background: rgba(255, 255, 255, 0.9);
21
+ padding: 30px;
22
+ border-radius: 20px;
23
+ box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
24
  position: relative;
25
+ overflow: hidden;
26
+ margin-bottom: 30px;
27
+ }
28
+ #app-header::before {
29
+ content: "";
30
+ position: absolute;
31
+ top: -50%;
32
+ left: -50%;
33
+ width: 200%;
34
+ height: 200%;
35
+ background: radial-gradient(circle, rgba(255,255,255,0.8) 0%, rgba(255,255,255,0) 70%);
36
+ animation: shimmer 10s infinite linear;
37
+ }
38
+ @keyframes shimmer {
39
+ 0% { transform: rotate(0deg); }
40
+ 100% { transform: rotate(360deg); }
41
  }
42
  #app-header h1 {
43
+ color: #6e48aa;
44
+ font-size: 2.5em;
45
+ margin-bottom: 15px;
46
+ text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
47
+ }
48
+ #app-header p {
49
+ font-size: 1.2em;
50
+ color: #555;
51
+ }
52
+ .concept-container {
53
+ display: flex;
54
+ justify-content: center;
55
+ gap: 30px;
56
+ margin-top: 30px;
57
+ flex-wrap: wrap;
58
  }
59
  .concept {
60
  position: relative;
61
+ transition: transform 0.3s, box-shadow 0.3s;
62
+ border-radius: 15px;
63
+ overflow: hidden;
64
+ background: white;
65
+ box-shadow: 0 5px 15px rgba(0,0,0,0.1);
66
  }
67
  .concept:hover {
68
+ transform: translateY(-10px) rotate(3deg);
69
+ box-shadow: 0 15px 30px rgba(0,0,0,0.2);
70
  }
71
  .concept img {
72
+ width: 120px;
73
+ height: 120px;
74
+ object-fit: cover;
75
+ border-radius: 15px 15px 0 0;
76
  }
77
  .concept-description {
78
+ background-color: #6e48aa;
 
 
 
 
79
  color: white;
80
+ padding: 10px;
81
+ font-size: 0.9em;
82
+ text-align: center;
 
 
 
 
83
  }
84
  .artifact {
85
  position: absolute;
86
+ background: radial-gradient(circle, rgba(255,255,255,0.8) 0%, rgba(255,255,255,0) 70%);
87
  border-radius: 50%;
88
+ opacity: 0.5;
89
  }
90
  .artifact.large {
91
+ width: 400px;
92
+ height: 400px;
93
+ top: -100px;
94
+ left: -200px;
95
+ animation: float 20s infinite ease-in-out;
96
  }
97
  .artifact.medium {
98
+ width: 300px;
99
+ height: 300px;
100
+ bottom: -150px;
101
+ right: -150px;
102
+ animation: float 15s infinite ease-in-out reverse;
103
  }
104
  .artifact.small {
105
+ width: 150px;
106
+ height: 150px;
107
  top: 50%;
108
  left: 50%;
109
  transform: translate(-50%, -50%);
110
+ animation: pulse 5s infinite alternate;
111
+ }
112
+ @keyframes float {
113
+ 0%, 100% { transform: translateY(0) rotate(0deg); }
114
+ 50% { transform: translateY(-20px) rotate(10deg); }
115
+ }
116
+ @keyframes pulse {
117
+ 0% { transform: scale(1); opacity: 0.5; }
118
+ 100% { transform: scale(1.1); opacity: 0.8; }
119
  }
120
  </style>
121
  <div id="app-header">
122
  <div class="artifact large"></div>
123
  <div class="artifact medium"></div>
124
  <div class="artifact small"></div>
125
+ <h1>Dreamscape Creator</h1>
126
+ <p>Unleash your imagination with AI-powered generative art</p>
127
+ <div class="concept-container">
128
  <div class="concept">
129
  <img src="https://example.com/illustration-style.jpg" alt="Illustration Style">
130
  <div class="concept-description">Illustration Style</div>
 
133
  <img src="https://example.com/line-art.jpg" alt="Line Art">
134
  <div class="concept-description">Line Art</div>
135
  </div>
136
+ <div class="concept">
137
+ <img src="https://example.com/midjourney-style.jpg" alt="Midjourney Style">
138
+ <div class="concept-description">Midjourney Style</div>
139
+ </div>
140
+ <div class="concept">
141
+ <img src="https://example.com/hanfu-anime-style.jpg" alt="Hanfu Anime">
142
+ <div class="concept-description">Hanfu Anime</div>
143
+ </div>
144
  </div>
145
  </div>
146
  """
 
245
  description = "Create unique artworks using Stable Diffusion with various styles and guidance methods."
246
 
247
  with gr.Blocks(css=HTML_TEMPLATE) as demo:
248
+ gr.HTML(HTML_TEMPLATE)
249
  with gr.Row():
250
+ text = gr.Textbox(label="Prompt", placeholder="Describe your dreamscape...")
251
  style = gr.Dropdown(label="Style", choices=list(style_token_dict.keys()), value="Illustration Style")
252
  with gr.Row():
253
+ inference_step = gr.Slider(1, 50, 20, step=1, label="Inference steps")
254
  guidance_scale = gr.Slider(1, 10, 7.5, step=0.1, label="Guidance scale")
255
  seed = gr.Slider(0, 10000, 42, step=1, label="Seed")
256
  with gr.Row():
257
  guidance_method = gr.Dropdown(label="Guidance method", choices=['Grayscale', 'Bright', 'Contrast', 'Symmetry', 'Saturation'], value="Grayscale")
258
  loss_scale = gr.Slider(100, 10000, 200, step=100, label="Loss scale")
259
  with gr.Row():
260
+ image_size = gr.Radio(["256x256", "512x512"], label="Image Size", value="256x256")
261
+ with gr.Row():
262
+ generate_button = gr.Button("Create Dreamscape", variant="primary")
263
  with gr.Row():
264
+ output_image = gr.Image(label="Your Dreamscape")
265
+ output_image_guided = gr.Image(label="Guided Dreamscape")
266
 
267
  generate_button.click(
268
  inference,
269
+ inputs=[text, style, inference_step, guidance_scale, seed, guidance_method, loss_scale, image_size],
270
  outputs=[output_image, output_image_guided]
271
  )
272
 
273
  gr.Examples(
274
  examples=[
275
+ ["A mystical floating island with cascading waterfalls and ethereal butterflies", 'Illustration Style', 20, 7.5, 42, 'Grayscale', 200, "256x256"]
276
  ],
277
+ inputs=[text, style, inference_step, guidance_scale, seed, guidance_method, loss_scale, image_size],
278
  outputs=[output_image, output_image_guided],
279
  fn=inference,
280
  cache_examples=True,
281
  )
282
 
283
+ demo.launch()