Staticaliza commited on
Commit
0563fad
·
verified ·
1 Parent(s): 6afc6a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -43,6 +43,11 @@ footer {
43
  '''
44
 
45
  # Functions
 
 
 
 
 
46
  def get_seed(seed):
47
  seed = seed.strip()
48
  if seed.isdigit():
@@ -53,9 +58,11 @@ def get_seed(seed):
53
  @spaces.GPU(duration=30)
54
  def generate(input=DEFAULT_INPUT, negative_input=DEFAULT_NEGATIVE_INPUT, height=DEFAULT_HEIGHT, width=DEFAULT_WIDTH, steps=1, guidance=0, seed=None):
55
 
 
 
56
  print(input, negative_input, height, width, steps, guidance, seed)
57
- model.to(DEVICE)
58
 
 
59
  parameters = {
60
  "prompt": input,
61
  "negative_prompt": negative_input,
@@ -63,13 +70,16 @@ def generate(input=DEFAULT_INPUT, negative_input=DEFAULT_NEGATIVE_INPUT, height=
63
  "width": width,
64
  "num_inference_steps": steps,
65
  "guidance_scale": guidance,
66
- "generator": torch.Generator().manual_seed(get_seed(seed)),
 
 
67
  "use_resolution_binning": True,
68
- #"output_type":"pil",
69
  }
70
 
71
  image = model(**parameters).images[0]
72
- return image
 
73
 
74
  def cloud():
75
  print("[CLOUD] | Space maintained.")
 
43
  '''
44
 
45
  # Functions
46
+ def save_image(img):
47
+ unique_name = str(uuid.uuid4()) + ".png"
48
+ img.save(unique_name)
49
+ return unique_name
50
+
51
  def get_seed(seed):
52
  seed = seed.strip()
53
  if seed.isdigit():
 
58
  @spaces.GPU(duration=30)
59
  def generate(input=DEFAULT_INPUT, negative_input=DEFAULT_NEGATIVE_INPUT, height=DEFAULT_HEIGHT, width=DEFAULT_WIDTH, steps=1, guidance=0, seed=None):
60
 
61
+ seed = get_seed(seed)
62
+
63
  print(input, negative_input, height, width, steps, guidance, seed)
 
64
 
65
+ model.to(DEVICE)
66
  parameters = {
67
  "prompt": input,
68
  "negative_prompt": negative_input,
 
70
  "width": width,
71
  "num_inference_steps": steps,
72
  "guidance_scale": guidance,
73
+ "num_images_per_prompt": 1,
74
+ "cross_attention_kwargs": {"scale": 0.65},
75
+ "generator": torch.Generator().manual_seed(seed),
76
  "use_resolution_binning": True,
77
+ "output_type":"pil",
78
  }
79
 
80
  image = model(**parameters).images[0]
81
+ image_paths = [save_image(img) for img in images]
82
+ return image_paths, seed
83
 
84
  def cloud():
85
  print("[CLOUD] | Space maintained.")