Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 = "
|
| 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 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 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 = [
|