Veda_Sahaja commited on
Commit
9da7937
·
1 Parent(s): 9b40850

Update space

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import numpy as np
3
  import random
4
- from diffusers import DiffusionPipeline
5
  import torch
6
  from typing import Tuple
7
 
@@ -70,7 +70,7 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
70
 
71
  if torch.cuda.is_available():
72
  # torch.cuda.max_memory_allocated(device=device)
73
- pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
74
  # pipe.enable_xformers_memory_efficient_attention()
75
  pipe = pipe.to(device)
76
  # else:
@@ -80,12 +80,14 @@ if torch.cuda.is_available():
80
  MAX_SEED = np.iinfo(np.int32).max
81
  MAX_IMAGE_SIZE = 1024
82
 
83
- def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
84
 
85
  if randomize_seed:
86
  seed = random.randint(0, MAX_SEED)
87
 
88
  generator = torch.Generator().manual_seed(seed)
 
 
89
 
90
  image = pipe(
91
  prompt = prompt,
@@ -209,7 +211,7 @@ with gr.Blocks(css=css) as demo:
209
 
210
  run_button.click(
211
  fn = infer,
212
- inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
213
  outputs = [result]
214
  )
215
 
 
1
  import gradio as gr
2
  import numpy as np
3
  import random
4
+ from diffusers import StableDiffusionXLPipeline
5
  import torch
6
  from typing import Tuple
7
 
 
70
 
71
  if torch.cuda.is_available():
72
  # torch.cuda.max_memory_allocated(device=device)
73
+ pipe = StableDiffusionXLPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
74
  # pipe.enable_xformers_memory_efficient_attention()
75
  pipe = pipe.to(device)
76
  # else:
 
80
  MAX_SEED = np.iinfo(np.int32).max
81
  MAX_IMAGE_SIZE = 1024
82
 
83
+ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, style_name=None):
84
 
85
  if randomize_seed:
86
  seed = random.randint(0, MAX_SEED)
87
 
88
  generator = torch.Generator().manual_seed(seed)
89
+
90
+ prompt, negative = apply_style(style_name, prompt, negative)
91
 
92
  image = pipe(
93
  prompt = prompt,
 
211
 
212
  run_button.click(
213
  fn = infer,
214
+ inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, style_selection],
215
  outputs = [result]
216
  )
217