inoculatemedia commited on
Commit
45e65a9
·
verified ·
1 Parent(s): d6c6405

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -35
app.py CHANGED
@@ -1,13 +1,15 @@
1
  import gradio as gr
2
  import numpy as np
3
  import random
4
-
5
  # import spaces #[uncomment to use ZeroGPU]
6
  from diffusers import DiffusionPipeline
7
  import torch
8
 
 
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
- model_repo_id = "stabilityai/sdxl-turbo" # Replace to the model you would like to use
11
 
12
  if torch.cuda.is_available():
13
  torch_dtype = torch.float16
@@ -16,39 +18,32 @@ else:
16
 
17
  pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
18
  pipe = pipe.to(device)
19
-
20
- MAX_SEED = np.iinfo(np.int32).max
21
- MAX_IMAGE_SIZE = 1024
22
-
23
-
24
- # @spaces.GPU #[uncomment to use ZeroGPU]
25
- def infer(
26
- prompt,
27
- negative_prompt,
28
- seed,
29
- randomize_seed,
30
- width,
31
- height,
32
- guidance_scale,
33
- num_inference_steps,
34
- progress=gr.Progress(track_tqdm=True),
35
- ):
36
- if randomize_seed:
37
- seed = random.randint(0, MAX_SEED)
38
-
39
- generator = torch.Generator().manual_seed(seed)
40
-
41
- image = pipe(
42
- prompt=prompt,
43
- negative_prompt=negative_prompt,
44
- guidance_scale=guidance_scale,
45
- num_inference_steps=num_inference_steps,
46
- width=width,
47
- height=height,
48
- generator=generator,
49
- ).images[0]
50
-
51
- return image, seed
52
 
53
 
54
  examples = [
 
1
  import gradio as gr
2
  import numpy as np
3
  import random
4
+ from diffusers import SemanticStableDiffusionPipeline
5
  # import spaces #[uncomment to use ZeroGPU]
6
  from diffusers import DiffusionPipeline
7
  import torch
8
 
9
+
10
+
11
  device = "cuda" if torch.cuda.is_available() else "cpu"
12
+ model_repo_id = "runwayml/stable-diffusion-v1-5" # Replace to the model you would like to use
13
 
14
  if torch.cuda.is_available():
15
  torch_dtype = torch.float16
 
18
 
19
  pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
20
  pipe = pipe.to(device)
21
+ pipe = SemanticStableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
22
+ pipe = pipe.to("cuda")
23
+
24
+ out = pipe(
25
+ prompt="a photo of the face of a woman",
26
+ num_images_per_prompt=1,
27
+ guidance_scale=7,
28
+ editing_prompt=[
29
+ "smiling, smile", # Concepts to apply
30
+ "glasses, wearing glasses",
31
+ "curls, wavy hair, curly hair",
32
+ "beard, full beard, mustache",
33
+ ],
34
+ reverse_editing_direction=[False, False, False, False], # Direction of guidance i.e. increase all concepts
35
+ edit_warmup_steps=[10, 10, 10, 10], # Warmup period for each concept
36
+ edit_guidance_scale=[4, 5, 5, 5.4], # Guidance scale for each concept
37
+ edit_threshold=[
38
+ 0.99,
39
+ 0.975,
40
+ 0.925,
41
+ 0.96,
42
+ ], # Threshold for each concept. Threshold equals the percentile of the latent space that will be discarded. I.e. threshold=0.99 uses 1% of the latent dimensions
43
+ edit_momentum_scale=0.3, # Momentum scale that will be added to the latent guidance
44
+ edit_mom_beta=0.6, # Momentum beta
45
+ edit_weights=[1, 1, 1, 1, 1], # Weights of the individual concepts against each other
46
+ )
 
 
 
 
 
 
 
47
 
48
 
49
  examples = [