KingNish commited on
Commit
909646e
1 Parent(s): 87dfbfe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -20
app.py CHANGED
@@ -10,7 +10,7 @@ from diffusers import DiffusionPipeline, StableDiffusionXLPipeline, EDMEulerSche
10
  from huggingface_hub import hf_hub_download, InferenceClient
11
 
12
  vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
13
- pipe = StableDiffusionXLPipeline.from_pretrained("SG161222/RealVisXL_V4.0", torch_dtype=torch.float16, vae=vae)
14
  pipe.load_lora_weights("KingNish/Better-Image-XL-Lora", weight_name="example-03.safetensors", adapter_name="lora")
15
  pipe.set_adapters("lora")
16
  pipe.to("cuda")
@@ -18,7 +18,9 @@ pipe.to("cuda")
18
  refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", vae=vae, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
19
  refiner.to("cuda")
20
 
21
- pipe_fast = StableDiffusionXLPipeline.from_pretrained("SG161222/RealVisXL_V3.0_Turbo", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
 
 
22
  pipe_fast.to("cuda")
23
 
24
  help_text = """
@@ -56,12 +58,13 @@ pipe_edit.to("cuda")
56
  def king(type ,
57
  input_image ,
58
  instruction: str ,
 
59
  steps: int = 25,
60
  randomize_seed: bool = False,
61
  seed: int = 2404,
62
  width: int = 1024,
63
  height: int = 1024,
64
- guidance_scale: float = 7,
65
  fast=True,
66
  use_resolution_binning: bool = True,
67
  progress=gr.Progress(track_tqdm=True),
@@ -72,7 +75,7 @@ def king(type ,
72
  seed = random.randint(0, 999999)
73
  generator = torch.manual_seed(seed)
74
  output_image = pipe_edit(
75
- instruction, image=raw_image,
76
  guidance_scale=guidance_scale, image_guidance_scale=1.5,
77
  num_inference_steps=steps, generator=generator, output_type="latent",
78
  ).images
@@ -90,11 +93,12 @@ def king(type ,
90
  generator = torch.Generator().manual_seed(seed)
91
  if fast:
92
  pipes=pipe_fast
93
- steps=int(steps/2)
94
  guidance_scale=(guidance_scale/3)
95
  else:
96
  pipes=pipe
97
  image = pipes( prompt = instruction,
 
98
  guidance_scale = guidance_scale,
99
  num_inference_steps = steps,
100
  width = width, height = height,
@@ -102,8 +106,9 @@ def king(type ,
102
  ).images
103
 
104
  refine = refiner( prompt=instruction,
105
- guidance_scale=guidance_scale,
106
- num_inference_steps=steps,
 
107
  image=image, generator=generator,
108
  ).images[0]
109
  return seed, refine
@@ -173,14 +178,12 @@ examples=[
173
  with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
174
  gr.Markdown("# Image Generator Pro")
175
  with gr.Row():
176
- with gr.Column(scale=2):
177
- instruction = gr.Textbox(lines=1, label="Instruction", interactive=True)
178
- with gr.Column(scale=1):
179
- generate_button = gr.Button("Generate")
180
  with gr.Row():
181
  type = gr.Dropdown(["Image Generation","Image Editing"], label="Task", value="Image Generation",interactive=True)
182
- enhance_prompt = gr.Checkbox(label="Enhance prompt", value = True)
183
- fast = gr.Checkbox(label="FAST Generation", value=True)
184
 
185
  with gr.Row():
186
  input_image = gr.Image(label="Image", type='filepath', interactive=True)
@@ -191,16 +194,11 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
191
 
192
  with gr.Accordion("Advanced options", open=False):
193
  with gr.Row():
194
- with gr.Column(scale=1):
195
- use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True, visible=True)
196
- with gr.Column(scale=2):
197
- negative_prompt = gr.Text(
198
  label="Negative prompt",
199
  max_lines=1,
200
- placeholder="Enter a negative prompt",
201
  value="(deformed iris, deformed pupils, semi-realistic, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, extra fingers, poorly drawn hands, poorly drawn face, deformed, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, (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, ugly, disgusting,",
202
- visible=True,
203
- )
204
  with gr.Row():
205
  width = gr.Slider( label="Width", minimum=256, maximum=2048, step=64, value=1024)
206
  height = gr.Slider( label="Height", minimum=256, maximum=2048, step=64, value=1024)
@@ -238,6 +236,7 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
238
  inputs=[type,
239
  input_image,
240
  instruction,
 
241
  steps,
242
  randomize_seed,
243
  seed,
 
10
  from huggingface_hub import hf_hub_download, InferenceClient
11
 
12
  vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
13
+ pipe = StableDiffusionXLPipeline.from_pretrained("fluently/Fluently-XL-Final", torch_dtype=torch.float16, vae=vae)
14
  pipe.load_lora_weights("KingNish/Better-Image-XL-Lora", weight_name="example-03.safetensors", adapter_name="lora")
15
  pipe.set_adapters("lora")
16
  pipe.to("cuda")
 
18
  refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", vae=vae, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
19
  refiner.to("cuda")
20
 
21
+ pipe_fast = StableDiffusionXLPipeline.from_pretrained("SG161222/RealVisXL_V3.0_Turbo", torch_dtype=torch.float16, vae=vae, use_safetensors=True, variant="fp16")
22
+ pipe_fast.load_lora_weights("KingNish/Better-Image-XL-Lora", weight_name="example-03.safetensors", adapter_name="lora")
23
+ pipe_fast.set_adapters("lora")
24
  pipe_fast.to("cuda")
25
 
26
  help_text = """
 
58
  def king(type ,
59
  input_image ,
60
  instruction: str ,
61
+ negative_prompt: str,
62
  steps: int = 25,
63
  randomize_seed: bool = False,
64
  seed: int = 2404,
65
  width: int = 1024,
66
  height: int = 1024,
67
+ guidance_scale: float = 6,
68
  fast=True,
69
  use_resolution_binning: bool = True,
70
  progress=gr.Progress(track_tqdm=True),
 
75
  seed = random.randint(0, 999999)
76
  generator = torch.manual_seed(seed)
77
  output_image = pipe_edit(
78
+ instruction, negative_prompt=negative_prompt, image=raw_image,
79
  guidance_scale=guidance_scale, image_guidance_scale=1.5,
80
  num_inference_steps=steps, generator=generator, output_type="latent",
81
  ).images
 
93
  generator = torch.Generator().manual_seed(seed)
94
  if fast:
95
  pipes=pipe_fast
96
+ steps=int(steps/3)
97
  guidance_scale=(guidance_scale/3)
98
  else:
99
  pipes=pipe
100
  image = pipes( prompt = instruction,
101
+ negative_prompt=negative_prompt,
102
  guidance_scale = guidance_scale,
103
  num_inference_steps = steps,
104
  width = width, height = height,
 
106
  ).images
107
 
108
  refine = refiner( prompt=instruction,
109
+ negative_prompt = negative_prompt,
110
+ guidance_scale = guidance_scale,
111
+ num_inference_steps= steps,
112
  image=image, generator=generator,
113
  ).images[0]
114
  return seed, refine
 
178
  with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
179
  gr.Markdown("# Image Generator Pro")
180
  with gr.Row():
181
+ instruction = gr.Textbox(lines=1, label="Instruction", interactive=True)
182
+ generate_button = gr.Button("Run", scale=0)
 
 
183
  with gr.Row():
184
  type = gr.Dropdown(["Image Generation","Image Editing"], label="Task", value="Image Generation",interactive=True)
185
+ enhance_prompt = gr.Checkbox(label="Enhance prompt", value = True, scale=0)
186
+ fast = gr.Checkbox(label="FAST Gen", value=True, scale=0)
187
 
188
  with gr.Row():
189
  input_image = gr.Image(label="Image", type='filepath', interactive=True)
 
194
 
195
  with gr.Accordion("Advanced options", open=False):
196
  with gr.Row():
197
+ negative_prompt = gr.Text(
 
 
 
198
  label="Negative prompt",
199
  max_lines=1,
 
200
  value="(deformed iris, deformed pupils, semi-realistic, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, extra fingers, poorly drawn hands, poorly drawn face, deformed, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, (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, ugly, disgusting,",
201
+ visible=True)
 
202
  with gr.Row():
203
  width = gr.Slider( label="Width", minimum=256, maximum=2048, step=64, value=1024)
204
  height = gr.Slider( label="Height", minimum=256, maximum=2048, step=64, value=1024)
 
236
  inputs=[type,
237
  input_image,
238
  instruction,
239
+ negative_prompt,
240
  steps,
241
  randomize_seed,
242
  seed,