naonauno commited on
Commit
fb70850
·
verified ·
1 Parent(s): a705099

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -14
app.py CHANGED
@@ -1,28 +1,38 @@
1
  import gradio as gr
2
  import torch
3
- from diffusers import StableDiffusionPipeline
4
- import os
5
- from huggingface_hub import login
6
- from safetensors.torch import load_file
7
 
8
- # Login using the token
9
- login(token=os.environ.get("HF_TOKEN"))
10
-
11
- # Initialize the pipeline with CPU
12
  model_id = "runwayml/stable-diffusion-v1-5"
13
  pipe = StableDiffusionPipeline.from_pretrained(
14
  model_id,
15
- torch_dtype=torch.float32,
16
- use_auth_token=os.environ.get("HF_TOKEN")
 
 
 
 
 
 
17
  )
 
18
 
19
- # Load your LoRA weights from local file
20
- lora_path = "models/40kHalf.safetensors" # Update this path to where you upload the file in your Space
21
- state_dict = load_file(lora_path)
22
- pipe.unet.load_attn_procs(state_dict)
 
 
 
 
 
23
 
24
  def generate_image(prompt, negative_prompt, guidance_scale, steps):
25
  with torch.no_grad():
 
 
 
26
  image = pipe(
27
  prompt=prompt,
28
  negative_prompt=negative_prompt,
 
1
  import gradio as gr
2
  import torch
3
+ from diffusers import StableDiffusionPipeline, UNet2DConditionModel
4
+ from diffusers.utils import load_image
 
 
5
 
6
+ # Initialize the base pipeline
 
 
 
7
  model_id = "runwayml/stable-diffusion-v1-5"
8
  pipe = StableDiffusionPipeline.from_pretrained(
9
  model_id,
10
+ torch_dtype=torch.float32
11
+ )
12
+
13
+ # Load the ControlNet UNet
14
+ unet = UNet2DConditionModel.from_pretrained(
15
+ "runwayml/stable-diffusion-v1-5",
16
+ subfolder="unet",
17
+ torch_dtype=torch.float32
18
  )
19
+ unet.add_extra_conditions(["canny"])
20
 
21
+ # Add the conditioning
22
+ pipe.unet = unet
23
+
24
+ # Load the ControlLoRA weights
25
+ pipe.load_lora_weights(
26
+ "models", # Local path to your ControlLoRA weights
27
+ weight_name="40kHalf.safetensors",
28
+ adapter_name="control_lora"
29
+ )
30
 
31
  def generate_image(prompt, negative_prompt, guidance_scale, steps):
32
  with torch.no_grad():
33
+ # Get canny edges (you'll need to implement this)
34
+ # For now, let's assume the input image processing is handled separately
35
+
36
  image = pipe(
37
  prompt=prompt,
38
  negative_prompt=negative_prompt,