KingNish commited on
Commit
96c3ec5
1 Parent(s): 944abe8

Solved Example Error issue

Browse files
Files changed (1) hide show
  1. app.py +32 -19
app.py CHANGED
@@ -4,6 +4,8 @@ import random
4
  from diffusers import AuraFlowPipeline
5
  import torch
6
  import spaces
 
 
7
 
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
9
 
@@ -28,37 +30,46 @@ pipe = AuraFlowPipeline.from_pretrained(
28
  MAX_SEED = np.iinfo(np.int32).max
29
  MAX_IMAGE_SIZE = 1024
30
 
 
 
 
 
 
31
  @spaces.GPU
32
- def infer(prompt, negative_prompt="", seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=5.0, num_inference_steps=28, progress=gr.Progress(track_tqdm=True)):
33
 
34
  if randomize_seed:
35
  seed = random.randint(0, MAX_SEED)
36
 
37
  generator = torch.Generator().manual_seed(seed)
38
 
39
- image = pipe(
40
- prompt = prompt,
41
- negative_prompt = negative_prompt,
42
- width=width,
43
- height=height,
44
- guidance_scale = guidance_scale,
45
- num_inference_steps = num_inference_steps,
46
- generator = generator
47
- ).images[0]
48
-
49
- return image, seed
50
 
51
  examples = [
52
  "A photo of a lavender cat",
53
- "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
54
- "An astronaut riding a green horse",
55
- "A delicious ceviche cheesecake slice",
 
 
 
 
56
  ]
57
 
 
58
  css="""
59
  #col-container {
60
  margin: 0 auto;
61
- max-width: 520px;
62
  }
63
  """
64
 
@@ -88,14 +99,16 @@ with gr.Blocks(css=css) as demo:
88
 
89
  run_button = gr.Button("Run", scale=0)
90
 
91
- result = gr.Image(label="Result", show_label=False)
92
 
93
  with gr.Accordion("Advanced Settings", open=False):
94
 
95
  negative_prompt = gr.Text(
96
  label="Negative prompt",
97
- max_lines=1,
 
98
  placeholder="Enter a negative prompt",
 
99
  )
100
 
101
  seed = gr.Slider(
@@ -149,7 +162,7 @@ with gr.Blocks(css=css) as demo:
149
  fn = infer,
150
  inputs = [prompt],
151
  outputs = [result, seed],
152
- cache_examples="lazy"
153
  )
154
 
155
  gr.on(
 
4
  from diffusers import AuraFlowPipeline
5
  import torch
6
  import spaces
7
+ import uuid
8
+ import os
9
 
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
11
 
 
30
  MAX_SEED = np.iinfo(np.int32).max
31
  MAX_IMAGE_SIZE = 1024
32
 
33
+ def save_image(img):
34
+ unique_name = str(uuid.uuid4()) + ".png"
35
+ img.save(unique_name)
36
+ return unique_name
37
+
38
  @spaces.GPU
39
+ def infer(prompt, negative_prompt="", seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=5.0, num_inference_steps=30, progress=gr.Progress(track_tqdm=True)):
40
 
41
  if randomize_seed:
42
  seed = random.randint(0, MAX_SEED)
43
 
44
  generator = torch.Generator().manual_seed(seed)
45
 
46
+ options = { "prompt" : prompt,
47
+ "negative_prompt" : negative_prompt,
48
+ "width":width,
49
+ "height":height,
50
+ "guidance_scale" : guidance_scale,
51
+ "num_inference_steps" : num_inference_steps,
52
+ "generator" : generator }
53
+ images = pipe(**options).images
54
+ image_paths = [save_image(img) for img in images]
55
+ return image_paths, seed
 
56
 
57
  examples = [
58
  "A photo of a lavender cat",
59
+ "Astronaut in a jungle grasping a sign board contain word 'I love SPACE', cold color palette, muted colors, detailed, 8k",
60
+ "a cat eating a piece of cheese",
61
+ "a ROBOT riding a BLUE horse on Mars, photorealistic",
62
+ "a cute robot artist painting on an easel, concept art",
63
+ "An alien grasping a sign board contain word 'AuraFlow', futuristic, neonpunk, detailed",
64
+ "Kids going to school, sketch",
65
+ "Logo of Company name SpaceY"
66
  ]
67
 
68
+
69
  css="""
70
  #col-container {
71
  margin: 0 auto;
72
+ max-width: 600px;
73
  }
74
  """
75
 
 
99
 
100
  run_button = gr.Button("Run", scale=0)
101
 
102
+ result = gr.Gallery(label="Result", columns=1, show_label=False)
103
 
104
  with gr.Accordion("Advanced Settings", open=False):
105
 
106
  negative_prompt = gr.Text(
107
  label="Negative prompt",
108
+ max_lines=5,
109
+ lines=4,
110
  placeholder="Enter a negative prompt",
111
+ value="(deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, NSFW",
112
  )
113
 
114
  seed = gr.Slider(
 
162
  fn = infer,
163
  inputs = [prompt],
164
  outputs = [result, seed],
165
+ cache_examples=True
166
  )
167
 
168
  gr.on(