Pclanglais commited on
Commit
e3d92e8
1 Parent(s): 9fcd704

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -27
app.py CHANGED
@@ -7,6 +7,24 @@ from diffusers import DiffusionPipeline, LCMScheduler
7
  from PIL import Image, ImageEnhance
8
  import io
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  @spaces.GPU
11
  def generate_image(prompt, num_inference_steps, guidance_scale):
12
  model_id = "stabilityai/stable-diffusion-xl-base-1.0"
@@ -60,39 +78,13 @@ def inpaint_image(prompt, init_image, mask_image, num_inference_steps, guidance_
60
 
61
  return image
62
 
63
- def generate_image_with_adapter(prompt, num_inference_steps, guidance_scale):
64
- pipe = DiffusionPipeline.from_pretrained(
65
- "stabilityai/stable-diffusion-xl-base-1.0",
66
- variant="fp16",
67
- torch_dtype=torch.float32
68
- ).to("cuda")
69
-
70
- # set scheduler
71
- pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
72
-
73
- # Load and fuse lcm lora
74
- pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl", adapter_name="lcm")
75
- pipe.load_lora_weights("Pclanglais/Mickey-1928", weight_name="pytorch_lora_weights.safetensors", adapter_name="mickey")
76
-
77
- # Combine LoRAs
78
- pipe.set_adapters(["lcm", "mickey"], adapter_weights=[1.0, 0.8])
79
- pipe.fuse_lora()
80
  generator = torch.manual_seed(0)
81
  # Generate the image
82
  image = pipe(prompt=prompt, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale, generator=generator).images[0]
83
- pipe.unfuse_lora()
84
  return image
85
 
86
 
87
- def modify_image(image, brightness, contrast):
88
- # Function to modify brightness and contrast
89
- image = Image.open(io.BytesIO(image))
90
- enhancer = ImageEnhance.Brightness(image)
91
- image = enhancer.enhance(brightness)
92
- enhancer = ImageEnhance.Contrast(image)
93
- image = enhancer.enhance(contrast)
94
- return image
95
-
96
  with gr.Blocks(gr.themes.Soft()) as demo:
97
  with gr.Row():
98
  image_output = gr.Image(label="Generated Image")
 
7
  from PIL import Image, ImageEnhance
8
  import io
9
 
10
+ pipe = DiffusionPipeline.from_pretrained(
11
+ "stabilityai/stable-diffusion-xl-base-1.0",
12
+ variant="fp16",
13
+ torch_dtype=torch.float32
14
+ ).to("cuda")
15
+
16
+ # set scheduler
17
+ pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
18
+
19
+ # Load and fuse lcm lora
20
+ pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl", adapter_name="lcm")
21
+ pipe.load_lora_weights("Pclanglais/wiki-model", weight_name="pytorch_lora_weights.safetensors", adapter_name="mickey")
22
+
23
+ # Combine LoRAs
24
+ pipe.set_adapters(["lcm", "mickey"], adapter_weights=[1.0, 1.0])
25
+ pipe.fuse_lora()
26
+
27
+
28
  @spaces.GPU
29
  def generate_image(prompt, num_inference_steps, guidance_scale):
30
  model_id = "stabilityai/stable-diffusion-xl-base-1.0"
 
78
 
79
  return image
80
 
81
+ def generate_image_with_adapter(pipe, prompt, num_inference_steps, guidance_scale):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  generator = torch.manual_seed(0)
83
  # Generate the image
84
  image = pipe(prompt=prompt, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale, generator=generator).images[0]
 
85
  return image
86
 
87
 
 
 
 
 
 
 
 
 
 
88
  with gr.Blocks(gr.themes.Soft()) as demo:
89
  with gr.Row():
90
  image_output = gr.Image(label="Generated Image")