developerskyebrowse commited on
Commit
7f9e35f
·
1 Parent(s): 62cc7ef
Files changed (1) hide show
  1. app.py +68 -232
app.py CHANGED
@@ -5,26 +5,23 @@ if prod:
5
  port = 8081
6
  # show_options = False
7
 
8
- import gc
9
  import os
 
10
  import random
11
  import time
12
-
13
  import gradio as gr
14
  import numpy as np
15
-
16
  # import imageio
17
  import torch
 
18
  from diffusers import (
19
- AutoencoderKL,
20
  ControlNetModel,
21
  DPMSolverMultistepScheduler,
22
  StableDiffusionControlNetPipeline,
 
23
  )
24
  from diffusers.models.attention_processor import AttnProcessor2_0
25
- from PIL import Image
26
  from preprocess import Preprocessor
27
-
28
  MAX_SEED = np.iinfo(np.int32).max
29
  API_KEY = os.environ.get("API_KEY", None)
30
 
@@ -34,7 +31,7 @@ compiled = False
34
  # api = HfApi()
35
 
36
  import spaces
37
-
38
  preprocessor = Preprocessor()
39
  preprocessor.load("NormalBae")
40
 
@@ -49,7 +46,7 @@ if gr.NO_RELOAD:
49
  torch_dtype=torch.float16,
50
  attn_implementation="flash_attention_2",
51
  ).to("cuda")
52
-
53
  # Scheduler
54
  scheduler = DPMSolverMultistepScheduler.from_pretrained(
55
  "runwayml/stable-diffusion-v1-5",
@@ -69,10 +66,10 @@ if gr.NO_RELOAD:
69
  # base_model_url = "https://huggingface.co/broyang/hentaidigitalart_v20/blob/main/realcartoon3d_v15.safetensors"
70
  base_model_url = "https://huggingface.co/Lykon/AbsoluteReality/blob/main/AbsoluteReality_1.8.1_pruned.safetensors"
71
  vae_url = "https://huggingface.co/stabilityai/sd-vae-ft-mse-original/blob/main/vae-ft-mse-840000-ema-pruned.safetensors"
72
-
73
  vae = AutoencoderKL.from_single_file(vae_url, torch_dtype=torch.float16).to("cuda")
74
- vae.to(memory_format=torch.channels_last)
75
-
76
  pipe = StableDiffusionControlNetPipeline.from_single_file(
77
  base_model_url,
78
  # safety_checker=None,
@@ -83,57 +80,23 @@ if gr.NO_RELOAD:
83
  torch_dtype=torch.float16,
84
  )
85
 
86
- pipe.load_textual_inversion(
87
- "broyang/hentaidigitalart_v20",
88
- weight_name="EasyNegativeV2.safetensors",
89
- token="EasyNegativeV2",
90
- )
91
- pipe.load_textual_inversion(
92
- "broyang/hentaidigitalart_v20", weight_name="badhandv4.pt", token="badhandv4"
93
- )
94
- pipe.load_textual_inversion(
95
- "broyang/hentaidigitalart_v20", weight_name="fcNeg-neg.pt", token="fcNeg-neg"
96
- )
97
- pipe.load_textual_inversion(
98
- "broyang/hentaidigitalart_v20", weight_name="HDA_Ahegao.pt", token="HDA_Ahegao"
99
- )
100
- pipe.load_textual_inversion(
101
- "broyang/hentaidigitalart_v20",
102
- weight_name="HDA_Bondage.pt",
103
- token="HDA_Bondage",
104
- )
105
- pipe.load_textual_inversion(
106
- "broyang/hentaidigitalart_v20",
107
- weight_name="HDA_pet_play.pt",
108
- token="HDA_pet_play",
109
- )
110
- pipe.load_textual_inversion(
111
- "broyang/hentaidigitalart_v20",
112
- weight_name="HDA_unconventional maid.pt",
113
- token="HDA_unconventional_maid",
114
- )
115
- pipe.load_textual_inversion(
116
- "broyang/hentaidigitalart_v20",
117
- weight_name="HDA_NakedHoodie.pt",
118
- token="HDA_NakedHoodie",
119
- )
120
- pipe.load_textual_inversion(
121
- "broyang/hentaidigitalart_v20",
122
- weight_name="HDA_NunDress.pt",
123
- token="HDA_NunDress",
124
- )
125
- pipe.load_textual_inversion(
126
- "broyang/hentaidigitalart_v20",
127
- weight_name="HDA_Shibari.pt",
128
- token="HDA_Shibari",
129
- )
130
  pipe.to("cuda")
131
-
132
  # experimental speedup?
133
  # pipe.compile()
134
  # torch.cuda.empty_cache()
135
  # gc.collect()
136
- print("---------------Loaded controlnet pipeline---------------")
137
 
138
  @spaces.GPU(duration=12)
139
  def init(pipe):
@@ -141,42 +104,21 @@ if gr.NO_RELOAD:
141
  pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
142
  pipe.unet.set_attn_processor(AttnProcessor2_0())
143
  print("Model Compiled!")
144
-
145
  init(pipe)
146
 
147
-
148
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
149
  if randomize_seed:
150
  seed = random.randint(0, MAX_SEED)
151
  return seed
152
 
153
-
154
  def get_additional_prompt():
155
  prompt = "hyperrealistic photography,extremely detailed,(intricate details),unity 8k wallpaper,ultra detailed"
156
  top = ["tank top", "blouse", "button up shirt", "sweater", "corset top"]
157
- bottom = [
158
- "short skirt",
159
- "athletic shorts",
160
- "jean shorts",
161
- "pleated skirt",
162
- "short skirt",
163
- "leggings",
164
- "high-waisted shorts",
165
- ]
166
- accessory = [
167
- "knee-high boots",
168
- "gloves",
169
- "Thigh-high stockings",
170
- "Garter belt",
171
- "choker",
172
- "necklace",
173
- "headband",
174
- "headphones",
175
- ]
176
  return f"{prompt}, {random.choice(top)}, {random.choice(bottom)}, {random.choice(accessory)}, score_9"
177
  # outfit = ["schoolgirl outfit", "playboy outfit", "red dress", "gala dress", "cheerleader outfit", "nurse outfit", "Kimono"]
178
 
179
-
180
  def get_prompt(prompt, additional_prompt):
181
  interior = "design-style interior designed (interior space), captured with a DSLR camera using f/10 aperture, 1/60 sec shutter speed, ISO 400, 20mm focal length, tungsten white balance, (sharp focus), professional photography, high-resolution, 8k, Pulitzer Prize-winning"
182
  default = "hyperrealistic photography,extremely detailed,(intricate details),unity 8k wallpaper,ultra detailed"
@@ -197,22 +139,9 @@ def get_prompt(prompt, additional_prompt):
197
  abg = "(1girl, asian body covered in words, words on body, tattoos of (words) on body),(masterpiece, best quality),medium breasts,(intricate details),unity 8k wallpaper,ultra detailed,(pastel colors),beautiful and aesthetic,see-through (clothes),detailed,solo"
198
  # shibari = "extremely detailed, hyperrealistic photography, earrings, blushing, lace choker, tattoo, medium hair, score_9, HDA_Shibari"
199
  shibari2 = "octane render, highly detailed, volumetric, HDA_Shibari"
200
-
201
  if prompt == "":
202
- girls = [
203
- randomize,
204
- pet_play,
205
- bondage,
206
- lab_girl,
207
- athleisure,
208
- atompunk,
209
- maid,
210
- nundress,
211
- naked_hoodie,
212
- abg,
213
- shibari2,
214
- ahegao2,
215
- ]
216
  prompts_nsfw = [abg, shibari2, ahegao2]
217
  prompt = f"{random.choice(girls)}"
218
  prompt = f"boho chic"
@@ -222,11 +151,19 @@ def get_prompt(prompt, additional_prompt):
222
  # prompt = default2
223
  return f"{prompt} f{additional_prompt}"
224
 
225
-
226
  style_list = [
227
- {"name": "None", "prompt": ""},
228
- {"name": "Minimalistic", "prompt": "Minimalistic"},
229
- {"name": "Boho Chic", "prompt": "boho chic"},
 
 
 
 
 
 
 
 
 
230
  {
231
  "name": "Saudi Prince Gold",
232
  "prompt": "saudi prince gold",
@@ -271,22 +208,17 @@ style_list = [
271
  "name": "Beach",
272
  "prompt": "Beach",
273
  },
274
- {
275
- "name": "The Matrix",
276
- "prompt": "Neon (atompunk world) retro cyberpunk background",
277
- },
278
  ]
279
 
280
  styles = {k["name"]: (k["prompt"]) for k in style_list}
281
  STYLE_NAMES = list(styles.keys())
282
 
283
-
284
  def apply_style(style_name):
285
  if style_name in styles:
286
  p = styles.get(style_name, "boho chic")
287
  return p
288
 
289
-
290
  css = """
291
  h1 {
292
  text-align: center;
@@ -334,7 +266,7 @@ with gr.Blocks(theme="bethecloud/storj_theme", css=css) as demo:
334
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
335
  a_prompt = gr.Textbox(
336
  label="Additional prompt",
337
- value="design-style interior designed (interior space), captured with a DSLR camera using f/10 aperture, 1/60 sec shutter speed, ISO 400, 20mm focal length, tungsten white balance, (sharp focus), professional photography, high-resolution, 8k, Pulitzer Prize-winning",
338
  )
339
  n_prompt = gr.Textbox(
340
  label="Negative prompt",
@@ -343,10 +275,7 @@ with gr.Blocks(theme="bethecloud/storj_theme", css=css) as demo:
343
  #############################################################################
344
  # input text
345
  with gr.Row():
346
- gr.Text(
347
- label="Interior Design Style Examples",
348
- 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.",
349
- )
350
  with gr.Column():
351
  prompt = gr.Textbox(
352
  label="Custom Prompt",
@@ -376,17 +305,15 @@ with gr.Blocks(theme="bethecloud/storj_theme", css=css) as demo:
376
  run_button = gr.Button(value="Use this one", size=["lg"], visible=False)
377
  # output image
378
  with gr.Column():
379
- result = gr.Image(
380
  label="Output",
381
  interactive=False,
382
  format="webp",
383
- show_share_button=False,
384
  )
385
  # Use this image button
386
  with gr.Column():
387
- use_ai_button = gr.Button(
388
- value="Use this one", size=["lg"], visible=False
389
- )
390
  config = [
391
  image,
392
  style_selection,
@@ -400,89 +327,22 @@ with gr.Blocks(theme="bethecloud/storj_theme", css=css) as demo:
400
  guidance_scale,
401
  seed,
402
  ]
403
-
404
  with gr.Row():
405
- helper_text = gr.Markdown(
406
- "## Tap and hold (on mobile) to save the image.", visible=True
407
- )
408
-
409
  # image processing
410
- @gr.on(
411
- triggers=[image.upload, prompt.submit, run_button.click],
412
- inputs=config,
413
- outputs=result,
414
- show_progress="minimal",
415
- )
416
- def auto_process_image(
417
- image,
418
- style_selection,
419
- prompt,
420
- a_prompt,
421
- n_prompt,
422
- num_images,
423
- image_resolution,
424
- preprocess_resolution,
425
- num_steps,
426
- guidance_scale,
427
- seed,
428
- progress=gr.Progress(track_tqdm=True),
429
- ):
430
- return process_image(
431
- image,
432
- style_selection,
433
- prompt,
434
- a_prompt,
435
- n_prompt,
436
- num_images,
437
- image_resolution,
438
- preprocess_resolution,
439
- num_steps,
440
- guidance_scale,
441
- seed,
442
- )
443
-
444
  # AI Image Processing
445
- @gr.on(
446
- triggers=[use_ai_button.click],
447
- inputs=config,
448
- outputs=result,
449
- show_progress="minimal",
450
- )
451
- def submit(
452
- image,
453
- style_selection,
454
- prompt,
455
- a_prompt,
456
- n_prompt,
457
- num_images,
458
- image_resolution,
459
- preprocess_resolution,
460
- num_steps,
461
- guidance_scale,
462
- seed,
463
- progress=gr.Progress(track_tqdm=True),
464
- ):
465
- return process_image(
466
- image,
467
- style_selection,
468
- prompt,
469
- a_prompt,
470
- n_prompt,
471
- num_images,
472
- image_resolution,
473
- preprocess_resolution,
474
- num_steps,
475
- guidance_scale,
476
- seed,
477
- )
478
 
479
  # Change input to result
480
- @gr.on(
481
- triggers=[use_ai_button.click],
482
- inputs=None,
483
- outputs=image,
484
- show_progress="hidden",
485
- )
486
  def update_input():
487
  try:
488
  print("Updating image to AI Temp Image")
@@ -491,28 +351,17 @@ with gr.Blocks(theme="bethecloud/storj_theme", css=css) as demo:
491
  except FileNotFoundError:
492
  print("No AI Image Available")
493
  return None
494
-
495
  # Turn off buttons when processing
496
- @gr.on(
497
- triggers=[image.upload, use_ai_button.click, run_button.click],
498
- inputs=None,
499
- outputs=[run_button, use_ai_button],
500
- show_progress="hidden",
501
- )
502
  def turn_buttons_off():
503
  return gr.update(visible=False), gr.update(visible=False)
504
-
505
  # Turn on buttons when processing is complete
506
- @gr.on(
507
- triggers=[result.change],
508
- inputs=None,
509
- outputs=[use_ai_button, run_button],
510
- show_progress="hidden",
511
- )
512
  def turn_buttons_on():
513
  return gr.update(visible=True), gr.update(visible=True)
514
 
515
-
516
  @spaces.GPU(duration=10)
517
  @torch.inference_mode()
518
  def process_image(
@@ -527,7 +376,7 @@ def process_image(
527
  num_steps,
528
  guidance_scale,
529
  seed,
530
- progress=gr.Progress(track_tqdm=True),
531
  ):
532
  torch.cuda.synchronize()
533
  preprocess_start = time.time()
@@ -539,7 +388,7 @@ def process_image(
539
  if not compiled:
540
  print("Not Compiled")
541
  compiled = True
542
-
543
  seed = random.randint(0, MAX_SEED)
544
  generator = torch.cuda.manual_seed(seed)
545
  control_image = preprocessor(
@@ -549,17 +398,10 @@ def process_image(
549
  )
550
  preprocess_time = time.time() - preprocess_start
551
  if style_selection is not None or style_selection != "None":
552
- prompt = (
553
- "Photo from Pinterest of "
554
- + apply_style(style_selection)
555
- + " "
556
- + prompt
557
- + " "
558
- + a_prompt
559
- )
560
  else:
561
- prompt = str(get_prompt(prompt, a_prompt))
562
- negative_prompt = str(n_prompt)
563
  print(prompt)
564
  start = time.time()
565
  results = pipe(
@@ -573,22 +415,18 @@ def process_image(
573
  ).images[0]
574
  torch.cuda.synchronize()
575
  torch.cuda.empty_cache()
576
- print(
577
- f"\n-------------------------Preprocess done in: {preprocess_time:.2f} seconds-------------------------"
578
- )
579
- print(
580
- f"\n-------------------------Inference done in: {time.time() - start:.2f} seconds-------------------------"
581
- )
582
-
583
  # timestamp = int(time.time())
584
- # if not os.path.exists("./outputs"):
585
  # os.makedirs("./outputs")
586
  # img_path = f"./{timestamp}.jpg"
587
  # results_path = f"./{timestamp}_out_{prompt}.jpg"
588
  # imageio.imsave(img_path, image)
589
  # results.save(results_path)
590
  results.save("temp_image.jpg")
591
-
592
  # api.upload_file(
593
  # path_or_fileobj=img_path,
594
  # path_in_repo=img_path,
@@ -607,9 +445,7 @@ def process_image(
607
  # )
608
 
609
  return results
610
-
611
-
612
  if prod:
613
  demo.queue(max_size=20).launch(server_name="localhost", server_port=port)
614
  else:
615
- demo.queue(api_open=False).launch(show_api=False)
 
5
  port = 8081
6
  # show_options = False
7
 
 
8
  import os
9
+ import gc
10
  import random
11
  import time
 
12
  import gradio as gr
13
  import numpy as np
 
14
  # import imageio
15
  import torch
16
+ from PIL import Image
17
  from diffusers import (
 
18
  ControlNetModel,
19
  DPMSolverMultistepScheduler,
20
  StableDiffusionControlNetPipeline,
21
+ AutoencoderKL,
22
  )
23
  from diffusers.models.attention_processor import AttnProcessor2_0
 
24
  from preprocess import Preprocessor
 
25
  MAX_SEED = np.iinfo(np.int32).max
26
  API_KEY = os.environ.get("API_KEY", None)
27
 
 
31
  # api = HfApi()
32
 
33
  import spaces
34
+
35
  preprocessor = Preprocessor()
36
  preprocessor.load("NormalBae")
37
 
 
46
  torch_dtype=torch.float16,
47
  attn_implementation="flash_attention_2",
48
  ).to("cuda")
49
+
50
  # Scheduler
51
  scheduler = DPMSolverMultistepScheduler.from_pretrained(
52
  "runwayml/stable-diffusion-v1-5",
 
66
  # base_model_url = "https://huggingface.co/broyang/hentaidigitalart_v20/blob/main/realcartoon3d_v15.safetensors"
67
  base_model_url = "https://huggingface.co/Lykon/AbsoluteReality/blob/main/AbsoluteReality_1.8.1_pruned.safetensors"
68
  vae_url = "https://huggingface.co/stabilityai/sd-vae-ft-mse-original/blob/main/vae-ft-mse-840000-ema-pruned.safetensors"
69
+
70
  vae = AutoencoderKL.from_single_file(vae_url, torch_dtype=torch.float16).to("cuda")
71
+ vae.to(memory_format=torch.channels_last)
72
+
73
  pipe = StableDiffusionControlNetPipeline.from_single_file(
74
  base_model_url,
75
  # safety_checker=None,
 
80
  torch_dtype=torch.float16,
81
  )
82
 
83
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="EasyNegativeV2.safetensors", token="EasyNegativeV2",)
84
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="badhandv4.pt", token="badhandv4")
85
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="fcNeg-neg.pt", token="fcNeg-neg")
86
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Ahegao.pt", token="HDA_Ahegao")
87
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Bondage.pt", token="HDA_Bondage")
88
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_pet_play.pt", token="HDA_pet_play")
89
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_unconventional maid.pt", token="HDA_unconventional_maid")
90
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NakedHoodie.pt", token="HDA_NakedHoodie")
91
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NunDress.pt", token="HDA_NunDress")
92
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Shibari.pt", token="HDA_Shibari")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  pipe.to("cuda")
94
+
95
  # experimental speedup?
96
  # pipe.compile()
97
  # torch.cuda.empty_cache()
98
  # gc.collect()
99
+ print("---------------Loaded controlnet pipeline---------------")
100
 
101
  @spaces.GPU(duration=12)
102
  def init(pipe):
 
104
  pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
105
  pipe.unet.set_attn_processor(AttnProcessor2_0())
106
  print("Model Compiled!")
 
107
  init(pipe)
108
 
 
109
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
110
  if randomize_seed:
111
  seed = random.randint(0, MAX_SEED)
112
  return seed
113
 
 
114
  def get_additional_prompt():
115
  prompt = "hyperrealistic photography,extremely detailed,(intricate details),unity 8k wallpaper,ultra detailed"
116
  top = ["tank top", "blouse", "button up shirt", "sweater", "corset top"]
117
+ bottom = ["short skirt", "athletic shorts", "jean shorts", "pleated skirt", "short skirt", "leggings", "high-waisted shorts"]
118
+ accessory = ["knee-high boots", "gloves", "Thigh-high stockings", "Garter belt", "choker", "necklace", "headband", "headphones"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  return f"{prompt}, {random.choice(top)}, {random.choice(bottom)}, {random.choice(accessory)}, score_9"
120
  # outfit = ["schoolgirl outfit", "playboy outfit", "red dress", "gala dress", "cheerleader outfit", "nurse outfit", "Kimono"]
121
 
 
122
  def get_prompt(prompt, additional_prompt):
123
  interior = "design-style interior designed (interior space), captured with a DSLR camera using f/10 aperture, 1/60 sec shutter speed, ISO 400, 20mm focal length, tungsten white balance, (sharp focus), professional photography, high-resolution, 8k, Pulitzer Prize-winning"
124
  default = "hyperrealistic photography,extremely detailed,(intricate details),unity 8k wallpaper,ultra detailed"
 
139
  abg = "(1girl, asian body covered in words, words on body, tattoos of (words) on body),(masterpiece, best quality),medium breasts,(intricate details),unity 8k wallpaper,ultra detailed,(pastel colors),beautiful and aesthetic,see-through (clothes),detailed,solo"
140
  # shibari = "extremely detailed, hyperrealistic photography, earrings, blushing, lace choker, tattoo, medium hair, score_9, HDA_Shibari"
141
  shibari2 = "octane render, highly detailed, volumetric, HDA_Shibari"
142
+
143
  if prompt == "":
144
+ girls = [randomize, pet_play, bondage, lab_girl, athleisure, atompunk, maid, nundress, naked_hoodie, abg, shibari2, ahegao2]
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  prompts_nsfw = [abg, shibari2, ahegao2]
146
  prompt = f"{random.choice(girls)}"
147
  prompt = f"boho chic"
 
151
  # prompt = default2
152
  return f"{prompt} f{additional_prompt}"
153
 
 
154
  style_list = [
155
+ {
156
+ "name": "None",
157
+ "prompt": ""
158
+ },
159
+ {
160
+ "name": "Minimalistic",
161
+ "prompt": "Minimalistic"
162
+ },
163
+ {
164
+ "name": "Boho Chic",
165
+ "prompt": "boho chic"
166
+ },
167
  {
168
  "name": "Saudi Prince Gold",
169
  "prompt": "saudi prince gold",
 
208
  "name": "Beach",
209
  "prompt": "Beach",
210
  },
 
 
 
 
211
  ]
212
 
213
  styles = {k["name"]: (k["prompt"]) for k in style_list}
214
  STYLE_NAMES = list(styles.keys())
215
 
 
216
  def apply_style(style_name):
217
  if style_name in styles:
218
  p = styles.get(style_name, "boho chic")
219
  return p
220
 
221
+
222
  css = """
223
  h1 {
224
  text-align: center;
 
266
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
267
  a_prompt = gr.Textbox(
268
  label="Additional prompt",
269
+ value = "design-style interior designed (interior space), captured with a DSLR camera using f/10 aperture, 1/60 sec shutter speed, ISO 400, 20mm focal length, tungsten white balance, (sharp focus), professional photography, high-resolution, 8k, Pulitzer Prize-winning"
270
  )
271
  n_prompt = gr.Textbox(
272
  label="Negative prompt",
 
275
  #############################################################################
276
  # input text
277
  with gr.Row():
278
+ 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.")
 
 
 
279
  with gr.Column():
280
  prompt = gr.Textbox(
281
  label="Custom Prompt",
 
305
  run_button = gr.Button(value="Use this one", size=["lg"], visible=False)
306
  # output image
307
  with gr.Column():
308
+ result = gr.Image(
309
  label="Output",
310
  interactive=False,
311
  format="webp",
312
+ show_share_button= False,
313
  )
314
  # Use this image button
315
  with gr.Column():
316
+ use_ai_button = gr.Button(value="Use this one", size=["lg"], visible=False)
 
 
317
  config = [
318
  image,
319
  style_selection,
 
327
  guidance_scale,
328
  seed,
329
  ]
330
+
331
  with gr.Row():
332
+ helper_text = gr.Markdown("## Tap and hold (on mobile) to save the image.", visible=True)
333
+
 
 
334
  # image processing
335
+ @gr.on(triggers=[image.upload, prompt.submit, run_button.click], inputs=config, outputs=result, show_progress="minimal")
336
+ def auto_process_image(image, style_selection, prompt, a_prompt, n_prompt, num_images, image_resolution, preprocess_resolution, num_steps, guidance_scale, seed, progress=gr.Progress(track_tqdm=True)):
337
+ return process_image(image, style_selection, prompt, a_prompt, n_prompt, num_images, image_resolution, preprocess_resolution, num_steps, guidance_scale, seed)
338
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
  # AI Image Processing
340
+ @gr.on(triggers=[use_ai_button.click], inputs=config, outputs=result, show_progress="minimal")
341
+ def submit(image, style_selection, prompt, a_prompt, n_prompt, num_images, image_resolution, preprocess_resolution, num_steps, guidance_scale, seed, progress=gr.Progress(track_tqdm=True)):
342
+ return process_image(image, style_selection, prompt, a_prompt, n_prompt, num_images, image_resolution, preprocess_resolution, num_steps, guidance_scale, seed)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
343
 
344
  # Change input to result
345
+ @gr.on(triggers=[use_ai_button.click], inputs=None, outputs=image, show_progress="hidden")
 
 
 
 
 
346
  def update_input():
347
  try:
348
  print("Updating image to AI Temp Image")
 
351
  except FileNotFoundError:
352
  print("No AI Image Available")
353
  return None
354
+
355
  # Turn off buttons when processing
356
+ @gr.on(triggers=[image.upload, use_ai_button.click, run_button.click], inputs=None, outputs=[run_button, use_ai_button], show_progress="hidden")
 
 
 
 
 
357
  def turn_buttons_off():
358
  return gr.update(visible=False), gr.update(visible=False)
359
+
360
  # Turn on buttons when processing is complete
361
+ @gr.on(triggers=[result.change], inputs=None, outputs=[use_ai_button, run_button], show_progress="hidden")
 
 
 
 
 
362
  def turn_buttons_on():
363
  return gr.update(visible=True), gr.update(visible=True)
364
 
 
365
  @spaces.GPU(duration=10)
366
  @torch.inference_mode()
367
  def process_image(
 
376
  num_steps,
377
  guidance_scale,
378
  seed,
379
+ progress=gr.Progress(track_tqdm=True)
380
  ):
381
  torch.cuda.synchronize()
382
  preprocess_start = time.time()
 
388
  if not compiled:
389
  print("Not Compiled")
390
  compiled = True
391
+
392
  seed = random.randint(0, MAX_SEED)
393
  generator = torch.cuda.manual_seed(seed)
394
  control_image = preprocessor(
 
398
  )
399
  preprocess_time = time.time() - preprocess_start
400
  if style_selection is not None or style_selection != "None":
401
+ prompt = "Photo from Pinterest of " + apply_style(style_selection) + " " + prompt + " " + a_prompt
 
 
 
 
 
 
 
402
  else:
403
+ prompt=str(get_prompt(prompt, a_prompt))
404
+ negative_prompt=str(n_prompt)
405
  print(prompt)
406
  start = time.time()
407
  results = pipe(
 
415
  ).images[0]
416
  torch.cuda.synchronize()
417
  torch.cuda.empty_cache()
418
+ print(f"\n-------------------------Preprocess done in: {preprocess_time:.2f} seconds-------------------------")
419
+ print(f"\n-------------------------Inference done in: {time.time() - start:.2f} seconds-------------------------")
420
+
 
 
 
 
421
  # timestamp = int(time.time())
422
+ #if not os.path.exists("./outputs"):
423
  # os.makedirs("./outputs")
424
  # img_path = f"./{timestamp}.jpg"
425
  # results_path = f"./{timestamp}_out_{prompt}.jpg"
426
  # imageio.imsave(img_path, image)
427
  # results.save(results_path)
428
  results.save("temp_image.jpg")
429
+
430
  # api.upload_file(
431
  # path_or_fileobj=img_path,
432
  # path_in_repo=img_path,
 
445
  # )
446
 
447
  return results
 
 
448
  if prod:
449
  demo.queue(max_size=20).launch(server_name="localhost", server_port=port)
450
  else:
451
+ demo.queue(api_open=False).launch(show_api=False)