CiaraRowles commited on
Commit
5891366
1 Parent(s): af168f5

Update controlnet/callable_functions.py

Browse files
Files changed (1) hide show
  1. controlnet/callable_functions.py +6 -12
controlnet/callable_functions.py CHANGED
@@ -10,22 +10,14 @@ from transformers import AutoProcessor, SiglipVisionModel
10
 
11
 
12
 
13
- def use_stylecode(model,image_path, prompt,negative_prompt, num_inference_steps, stylecode,image=None):
14
  # Load and preprocess image
15
  # Set up model components
16
  unet = UNet2DConditionModel.from_pretrained("runwayml/stable-diffusion-v1-5", subfolder="unet", torch_dtype=torch.float16, device="cuda")
17
  stylecodes_model = StyleCodesModel.from_unet(unet, size_ratio=1.0).to(dtype=torch.float16, device="cuda")
18
 
19
- noise_scheduler = DDIMScheduler(
20
- num_train_timesteps=1000,
21
- beta_start=0.00085,
22
- beta_end=0.012,
23
- beta_schedule="scaled_linear",
24
- clip_sample=False,
25
- set_alpha_to_one=False,
26
- steps_offset=1,
27
- )
28
 
 
29
  stylecodes_model.load_model(model)
30
 
31
  pipe = StableDiffusionPipelineXSv2.from_pretrained(
@@ -46,8 +38,10 @@ def use_stylecode(model,image_path, prompt,negative_prompt, num_inference_steps,
46
  image = image.resize((512, 512))
47
 
48
  # Set up generator with a fixed seed for reproducibility
49
- seed = 238
50
- generator = torch.Generator(device="cuda").manual_seed(seed)
 
 
51
 
52
  # Run the image through the pipeline with the specified prompt
53
  output_images = pipe(
 
10
 
11
 
12
 
13
+ def use_stylecode(model,image_path, prompt,negative_prompt, num_inference_steps, stylecode,seed=None,image=None):
14
  # Load and preprocess image
15
  # Set up model components
16
  unet = UNet2DConditionModel.from_pretrained("runwayml/stable-diffusion-v1-5", subfolder="unet", torch_dtype=torch.float16, device="cuda")
17
  stylecodes_model = StyleCodesModel.from_unet(unet, size_ratio=1.0).to(dtype=torch.float16, device="cuda")
18
 
 
 
 
 
 
 
 
 
 
19
 
20
+ print("running prompt = ",prompt, " negative_prompt = ",negative_prompt, " with code ", stylecode)
21
  stylecodes_model.load_model(model)
22
 
23
  pipe = StableDiffusionPipelineXSv2.from_pretrained(
 
38
  image = image.resize((512, 512))
39
 
40
  # Set up generator with a fixed seed for reproducibility
41
+ if seed is not None and not -1:
42
+ generator = torch.Generator(device="cuda").manual_seed(seed)
43
+ else:
44
+ generator = None
45
 
46
  # Run the image through the pipeline with the specified prompt
47
  output_images = pipe(