developerskyebrowse commited on
Commit
843171c
·
1 Parent(s): c5fdec1
Files changed (2) hide show
  1. local_app.py +55 -62
  2. web.html +159 -0
local_app.py CHANGED
@@ -28,11 +28,10 @@ API_KEY = os.environ.get("API_KEY", None)
28
  print("CUDA version:", torch.version.cuda)
29
  print("loading pipe")
30
  compiled = False
31
-
32
- preprocessor = Preprocessor()
33
- preprocessor.load("NormalBae")
34
 
35
  if gr.NO_RELOAD:
 
 
36
  torch.cuda.max_memory_allocated(device="cuda")
37
 
38
  # Controlnet Normal
@@ -66,16 +65,7 @@ if gr.NO_RELOAD:
66
 
67
  vae = AutoencoderKL.from_single_file(vae_url, torch_dtype=torch.float16).to("cuda")
68
  vae.to(memory_format=torch.channels_last)
69
-
70
- # pipe = StableDiffusionControlNetPipeline.from_pretrained(
71
- # base_model_id,
72
- # safety_checker=None,
73
- # controlnet=controlnet,
74
- # scheduler=scheduler,
75
- # vae=vae,
76
- # torch_dtype=torch.float16,
77
- # ).to("cuda")
78
-
79
  pipe = StableDiffusionControlNetPipeline.from_single_file(
80
  base_model_url,
81
  controlnet=controlnet,
@@ -96,15 +86,9 @@ if gr.NO_RELOAD:
96
  pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Shibari.pt", token="HDA_Shibari")
97
  pipe.to("cuda")
98
 
99
- # experimental speedup?
100
- # pipe.compile()
101
- # torch.cuda.empty_cache()
102
- # gc.collect()
103
  print("---------------Loaded controlnet pipeline---------------")
104
 
105
  # @spaces.GPU(duration=12)
106
- # pipe.enable_xformers_memory_efficient_attention()
107
- # pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
108
  pipe.unet.set_attn_processor(AttnProcessor2_0())
109
  torch.cuda.empty_cache()
110
  gc.collect()
@@ -161,7 +145,7 @@ style_list = [
161
  "prompt": ""
162
  },
163
  {
164
- "name": "Minimalistic",
165
  "prompt": "Minimalist interior design, clean lines, neutral colors, uncluttered space, functional furniture, lots of natural light"
166
  },
167
  {
@@ -169,12 +153,12 @@ style_list = [
169
  "prompt": "Bohemian chic interior, eclectic mix of patterns and textures, vintage furniture, plants, woven textiles, warm earthy colors"
170
  },
171
  {
172
- "name": "Saudi Prince Gold",
173
- "prompt": "Opulent gold interior, luxurious ornate furniture, crystal chandeliers, rich fabrics, marble floors, intricate Arabic patterns"
174
  },
175
  {
176
- "name": "Modern Farmhouse",
177
- "prompt": "Modern farmhouse interior, rustic wood elements, shiplap walls, neutral color palette, industrial accents, cozy textiles"
178
  },
179
  {
180
  "name": "Neoclassical",
@@ -185,11 +169,11 @@ style_list = [
185
  "prompt": "Eclectic interior design, mix of styles and eras, bold color combinations, diverse furniture pieces, unique art objects"
186
  },
187
  {
188
- "name": "Parisian White",
189
  "prompt": "Parisian apartment interior, all-white color scheme, ornate moldings, herringbone wood floors, elegant furniture, large windows"
190
  },
191
  {
192
- "name": "Hollywood Glam",
193
  "prompt": "Hollywood Regency interior, glamorous and luxurious, bold colors, mirrored surfaces, velvet upholstery, gold accents"
194
  },
195
  {
@@ -197,27 +181,27 @@ style_list = [
197
  "prompt": "Scandinavian interior design, light wood tones, white walls, minimalist furniture, cozy textiles, hygge atmosphere"
198
  },
199
  {
200
- "name": "Japanese",
201
- "prompt": "Traditional Japanese interior, tatami mats, shoji screens, low furniture, zen garden view, minimalist decor, natural materials"
202
  },
203
  {
204
- "name": "Texas Cowboy",
205
- "prompt": "Western cowboy interior, rustic wood beams, leather furniture, cowhide rugs, antler chandeliers, southwestern patterns"
206
  },
207
- {
208
  "name": "Midcentury Modern",
209
  "prompt": "Mid-century modern interior, 1950s-60s style furniture, organic shapes, warm wood tones, bold accent colors, large windows"
210
  },
211
- {
212
- "name": "Beach",
213
- "prompt": "Coastal beach house interior, light blue and white color scheme, weathered wood, nautical accents, sheer curtains, ocean view"
214
- },
215
  {
216
  "name": "Retro Futurism",
217
  "prompt": "Neon (atompunk world) retro cyberpunk background",
218
  },
219
  {
220
- "name": "The Matrix",
 
 
 
 
221
  "prompt": "Futuristic cyberpunk interior, neon accent lighting, holographic plants, sleek black surfaces, advanced gaming setup, transparent screens, Blade Runner inspired decor, high-tech minimalist furniture"
222
  }
223
  ]
@@ -229,27 +213,40 @@ def apply_style(style_name):
229
  if style_name in styles:
230
  p = styles.get(style_name, "boho chic")
231
  return p
232
-
233
-
234
  css = """
235
- h1 {
236
  text-align: center;
237
- display:block;
238
  }
239
- h2 {
240
- text-align: center;
241
- display:block;
242
  }
243
- h3 {
244
- text-align: center;
245
- display:block;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  }
247
- .gradio-container{max-width: 1800px !important}
248
- footer {visibility: hidden}
249
  """
250
  with gr.Blocks(theme="bethecloud/storj_theme", css=css) as demo:
251
  #############################################################################
252
- with gr.Row():
253
  with gr.Accordion("Advanced options", open=show_options, visible=show_options):
254
  num_images = gr.Slider(
255
  label="Images", minimum=1, maximum=4, value=1, step=1
@@ -290,11 +287,11 @@ with gr.Blocks(theme="bethecloud/storj_theme", css=css) as demo:
290
  # gr.Text(label="Interior Design Style Examples", value="Eclectic, Maximalist, Bohemian, Scandinavian, Minimalist, Rustic, Modern Farmhouse, Contemporary, Luxury, Airbnb, Boho Chic, Midcentury Modern, Art Deco, Zen, Beach, Neoclassical, Industrial, Biophilic, Eco-friendly, Hollywood Glam, Parisian White, Saudi Prince Gold, French Country, Monster Energy Drink, Cyberpunk, Vaporwave, Baroque, etc.\n\nPro tip: add a color to customize it! You can also describe the furniture type.")
291
  with gr.Column():
292
  prompt = gr.Textbox(
293
- label="Custom Prompt",
294
- placeholder="boho chic",
295
  )
296
- with gr.Row(visible=True):
297
- style_selection = gr.Radio(
298
  show_label=True,
299
  container=True,
300
  interactive=True,
@@ -302,9 +299,8 @@ with gr.Blocks(theme="bethecloud/storj_theme", css=css) as demo:
302
  value="None",
303
  label="Design Styles",
304
  )
305
- # input image
306
- with gr.Row(equal_height=True):
307
- with gr.Column(scale=1, min_width=300):
308
  image = gr.Image(
309
  label="Input",
310
  sources=["upload"],
@@ -312,20 +308,17 @@ with gr.Blocks(theme="bethecloud/storj_theme", css=css) as demo:
312
  mirror_webcam=True,
313
  format="webp",
314
  )
315
- # run button
316
  with gr.Column():
317
- run_button = gr.Button(value="Use this one", size="lg", visible=False)
318
- # output image
319
- with gr.Column(scale=1, min_width=300):
320
  result = gr.Image(
321
  label="Output",
322
  interactive=False,
323
  format="webp",
324
  show_share_button= False,
325
  )
326
- # Use this image button
327
  with gr.Column():
328
- use_ai_button = gr.Button(value="Use this one", size="lg", visible=False)
329
  config = [
330
  image,
331
  style_selection,
 
28
  print("CUDA version:", torch.version.cuda)
29
  print("loading pipe")
30
  compiled = False
 
 
 
31
 
32
  if gr.NO_RELOAD:
33
+ preprocessor = Preprocessor()
34
+ preprocessor.load("NormalBae")
35
  torch.cuda.max_memory_allocated(device="cuda")
36
 
37
  # Controlnet Normal
 
65
 
66
  vae = AutoencoderKL.from_single_file(vae_url, torch_dtype=torch.float16).to("cuda")
67
  vae.to(memory_format=torch.channels_last)
68
+
 
 
 
 
 
 
 
 
 
69
  pipe = StableDiffusionControlNetPipeline.from_single_file(
70
  base_model_url,
71
  controlnet=controlnet,
 
86
  pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Shibari.pt", token="HDA_Shibari")
87
  pipe.to("cuda")
88
 
 
 
 
 
89
  print("---------------Loaded controlnet pipeline---------------")
90
 
91
  # @spaces.GPU(duration=12)
 
 
92
  pipe.unet.set_attn_processor(AttnProcessor2_0())
93
  torch.cuda.empty_cache()
94
  gc.collect()
 
145
  "prompt": ""
146
  },
147
  {
148
+ "name": "Minimal",
149
  "prompt": "Minimalist interior design, clean lines, neutral colors, uncluttered space, functional furniture, lots of natural light"
150
  },
151
  {
 
153
  "prompt": "Bohemian chic interior, eclectic mix of patterns and textures, vintage furniture, plants, woven textiles, warm earthy colors"
154
  },
155
  {
156
+ "name": "Farmhouse",
157
+ "prompt": "Modern farmhouse interior, rustic wood elements, shiplap walls, neutral color palette, industrial accents, cozy textiles"
158
  },
159
  {
160
+ "name": "Saudi Prince",
161
+ "prompt": "Opulent gold interior, luxurious ornate furniture, crystal chandeliers, rich fabrics, marble floors, intricate Arabic patterns"
162
  },
163
  {
164
  "name": "Neoclassical",
 
169
  "prompt": "Eclectic interior design, mix of styles and eras, bold color combinations, diverse furniture pieces, unique art objects"
170
  },
171
  {
172
+ "name": "Parisian",
173
  "prompt": "Parisian apartment interior, all-white color scheme, ornate moldings, herringbone wood floors, elegant furniture, large windows"
174
  },
175
  {
176
+ "name": "Hollywood",
177
  "prompt": "Hollywood Regency interior, glamorous and luxurious, bold colors, mirrored surfaces, velvet upholstery, gold accents"
178
  },
179
  {
 
181
  "prompt": "Scandinavian interior design, light wood tones, white walls, minimalist furniture, cozy textiles, hygge atmosphere"
182
  },
183
  {
184
+ "name": "Beach",
185
+ "prompt": "Coastal beach house interior, light blue and white color scheme, weathered wood, nautical accents, sheer curtains, ocean view"
186
  },
187
  {
188
+ "name": "Japanese",
189
+ "prompt": "Traditional Japanese interior, tatami mats, shoji screens, low furniture, zen garden view, minimalist decor, natural materials"
190
  },
191
+ {
192
  "name": "Midcentury Modern",
193
  "prompt": "Mid-century modern interior, 1950s-60s style furniture, organic shapes, warm wood tones, bold accent colors, large windows"
194
  },
 
 
 
 
195
  {
196
  "name": "Retro Futurism",
197
  "prompt": "Neon (atompunk world) retro cyberpunk background",
198
  },
199
  {
200
+ "name": "Texan",
201
+ "prompt": "Western cowboy interior, rustic wood beams, leather furniture, cowhide rugs, antler chandeliers, southwestern patterns"
202
+ },
203
+ {
204
+ "name": "Matrix",
205
  "prompt": "Futuristic cyberpunk interior, neon accent lighting, holographic plants, sleek black surfaces, advanced gaming setup, transparent screens, Blade Runner inspired decor, high-tech minimalist furniture"
206
  }
207
  ]
 
213
  if style_name in styles:
214
  p = styles.get(style_name, "boho chic")
215
  return p
216
+
 
217
  css = """
218
+ h1, h2, h3 {
219
  text-align: center;
220
+ display: block;
221
  }
222
+
223
+ .gradio-container {
224
+ max-width: 1200px !important;
225
  }
226
+
227
+ footer {
228
+ visibility: hidden;
229
+ }
230
+
231
+ .gr-image {
232
+ display: flex;
233
+ justify-content: center;
234
+ align-items: center;
235
+ width: 100%;
236
+ height: 512px;
237
+ overflow: hidden;
238
+ }
239
+
240
+ .gr-image img {
241
+ width: 100%;
242
+ height: 100%;
243
+ object-fit: cover;
244
+ object-position: center;
245
  }
 
 
246
  """
247
  with gr.Blocks(theme="bethecloud/storj_theme", css=css) as demo:
248
  #############################################################################
249
+ with gr.Row():
250
  with gr.Accordion("Advanced options", open=show_options, visible=show_options):
251
  num_images = gr.Slider(
252
  label="Images", minimum=1, maximum=4, value=1, step=1
 
287
  # gr.Text(label="Interior Design Style Examples", value="Eclectic, Maximalist, Bohemian, Scandinavian, Minimalist, Rustic, Modern Farmhouse, Contemporary, Luxury, Airbnb, Boho Chic, Midcentury Modern, Art Deco, Zen, Beach, Neoclassical, Industrial, Biophilic, Eco-friendly, Hollywood Glam, Parisian White, Saudi Prince Gold, French Country, Monster Energy Drink, Cyberpunk, Vaporwave, Baroque, etc.\n\nPro tip: add a color to customize it! You can also describe the furniture type.")
288
  with gr.Column():
289
  prompt = gr.Textbox(
290
+ label="Custom Prompt (optional)",
291
+ placeholder="use your imagination 👀",
292
  )
293
+ with gr.Column(visible=True):
294
+ style_selection = gr.Dropdown(
295
  show_label=True,
296
  container=True,
297
  interactive=True,
 
299
  value="None",
300
  label="Design Styles",
301
  )
302
+ with gr.Row(equal_height=True, variant="panel"):
303
+ with gr.Column(min_width=300):
 
304
  image = gr.Image(
305
  label="Input",
306
  sources=["upload"],
 
308
  mirror_webcam=True,
309
  format="webp",
310
  )
 
311
  with gr.Column():
312
+ run_button = gr.Button(value="Use this one", size="sm", visible=False)
313
+ with gr.Column(min_width=300):
 
314
  result = gr.Image(
315
  label="Output",
316
  interactive=False,
317
  format="webp",
318
  show_share_button= False,
319
  )
 
320
  with gr.Column():
321
+ use_ai_button = gr.Button(value="Use this one", size="sm", visible=False)
322
  config = [
323
  image,
324
  style_selection,
web.html ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Gradio App Embed</title>
7
+ <script type="module" src="https://gradio.s3-us-west-2.amazonaws.com/4.37.2/gradio.js"></script>
8
+ <style>
9
+ body, html {
10
+ margin: 0;
11
+ padding: 0;
12
+ width: 100%;
13
+ height: 100%;
14
+ }
15
+ .gradio-container {
16
+ width: 100%;
17
+ min-height: 600px;
18
+ display: flex;
19
+ justify-content: center;
20
+ align-items: center;
21
+ margin: 0 auto;
22
+ padding: 20px;
23
+ box-sizing: border-box;
24
+ }
25
+ gradio-app {
26
+ width: 100%;
27
+ max-width: 1024px;
28
+ height: auto;
29
+ border: 1px solid #e0e0e0;
30
+ border-radius: 8px;
31
+ overflow: visible;
32
+ }
33
+ gradio-app::part(root) {
34
+ max-width: 100% !important;
35
+ }
36
+ gradio-app::part(root) h1,
37
+ gradio-app::part(root) h2,
38
+ gradio-app::part(root) h3 {
39
+ text-align: center;
40
+ display: block;
41
+ }
42
+ gradio-app::part(root) .gr-image {
43
+ display: flex;
44
+ justify-content: center;
45
+ align-items: center;
46
+ width: 100%;
47
+ height: 512px;
48
+ overflow: hidden;
49
+ }
50
+ gradio-app::part(root) .gr-image img {
51
+ width: 100%;
52
+ height: 100%;
53
+ object-fit: cover;
54
+ object-position: center;
55
+ }
56
+ gradio-app::part(root) footer {
57
+ display: none !important;
58
+ }
59
+ gradio-app::part(root) .gr-button-row {
60
+ justify-content: center;
61
+ }
62
+ gradio-app::part(root) .gr-form.gr-box {
63
+ max-width: 100% !important;
64
+ }
65
+ gradio-app::part(root) #style_selection {
66
+ width: 100%;
67
+ max-width: 300px;
68
+ margin: 0 auto;
69
+ }
70
+ gradio-app::part(root) .gr-form {
71
+ display: flex;
72
+ flex-direction: column;
73
+ align-items: center;
74
+ }
75
+ #mobile-dropdown {
76
+ display: none;
77
+ width: 100%;
78
+ max-width: 300px;
79
+ margin: 10px auto;
80
+ padding: 10px;
81
+ font-size: 16px;
82
+ }
83
+ @media (max-width: 768px) {
84
+ #mobile-dropdown {
85
+ display: block;
86
+ }
87
+ gradio-app::part(root) #style_selection {
88
+ display: none;
89
+ }
90
+ }
91
+ </style>
92
+ </head>
93
+ <body>
94
+ <div class="gradio-container">
95
+ <gradio-app src="https://app.skybrowse.co"></gradio-app>
96
+ </div>
97
+ <select id="mobile-dropdown"></select>
98
+ <script>
99
+ document.addEventListener('DOMContentLoaded', (event) => {
100
+ const gradioApp = document.querySelector('gradio-app');
101
+ const container = document.querySelector('.gradio-container');
102
+ const mobileDropdown = document.getElementById('mobile-dropdown');
103
+
104
+ const adjustLayout = () => {
105
+ const shadowRoot = gradioApp.shadowRoot;
106
+ if (shadowRoot) {
107
+ const appContent = shadowRoot.querySelector('#root');
108
+ if (appContent) {
109
+ container.style.minHeight = `${window.innerHeight}px`;
110
+ appContent.style.minHeight = `${window.innerHeight}px`;
111
+
112
+ // Create mobile dropdown
113
+ const radioGroup = shadowRoot.querySelector('#style_selection');
114
+ if (radioGroup) {
115
+ const radioButtons = radioGroup.querySelectorAll('input[type="radio"]');
116
+ mobileDropdown.innerHTML = '';
117
+ radioButtons.forEach(radio => {
118
+ const option = document.createElement('option');
119
+ option.value = radio.value;
120
+ option.textContent = radio.nextElementSibling.textContent;
121
+ mobileDropdown.appendChild(option);
122
+ });
123
+
124
+ // Sync dropdown with radio buttons
125
+ mobileDropdown.addEventListener('change', (e) => {
126
+ const selectedRadio = radioGroup.querySelector(`input[value="${e.target.value}"]`);
127
+ if (selectedRadio) selectedRadio.click();
128
+ });
129
+
130
+ // Position the dropdown
131
+ const radioGroupRect = radioGroup.getBoundingClientRect();
132
+ mobileDropdown.style.position = 'absolute';
133
+ mobileDropdown.style.top = `${radioGroupRect.top}px`;
134
+ mobileDropdown.style.left = `${radioGroupRect.left}px`;
135
+ mobileDropdown.style.width = `${radioGroupRect.width}px`;
136
+ }
137
+
138
+ // Force layout recalculation
139
+ appContent.style.display = 'none';
140
+ appContent.offsetHeight; // Trigger reflow
141
+ appContent.style.display = '';
142
+ }
143
+ }
144
+ };
145
+
146
+ const observer = new MutationObserver((mutations) => {
147
+ adjustLayout();
148
+ });
149
+
150
+ gradioApp.addEventListener('load', () => {
151
+ observer.observe(gradioApp.shadowRoot, { childList: true, subtree: true });
152
+ adjustLayout();
153
+ });
154
+
155
+ window.addEventListener('resize', adjustLayout);
156
+ });
157
+ </script>
158
+ </body>
159
+ </html>