Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,65 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
-
|
4 |
|
5 |
-
|
6 |
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
|
17 |
-
|
18 |
-
processed_df, sensitive_cols = process.process_data(df)
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
if st.checkbox("Apply k-anonymity"):
|
34 |
-
k = st.number_input("Enter the value of k", min_value=1)
|
35 |
-
processed_df = process.apply_k_anonymity(processed_df, k)
|
36 |
-
|
37 |
-
st.write("Final Processed Data:")
|
38 |
-
st.write(processed_df)
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from semdiffusers import SemanticEditPipeline
|
4 |
|
5 |
+
device='cuda'
|
6 |
|
7 |
+
pipe = SemanticEditPipeline.from_pretrained(
|
8 |
+
"runwayml/stable-diffusion-v1-5",
|
9 |
+
).to(device)
|
10 |
|
11 |
+
def infer(prompt, seed):
|
12 |
+
gen = torch.Generator(device=device)
|
13 |
+
gen.manual_seed(seed)
|
14 |
+
|
15 |
+
out = pipe(
|
16 |
+
prompt=prompt,
|
17 |
+
generator=gen,
|
18 |
+
num_images_per_prompt=1,
|
19 |
+
guidance_scale=7
|
20 |
+
)
|
21 |
+
|
22 |
+
images = out.images[0]
|
23 |
+
|
24 |
+
out_edit = pipe(
|
25 |
+
prompt=prompt,
|
26 |
+
generator=gen,
|
27 |
+
num_images_per_prompt=1,
|
28 |
+
guidance_scale=7,
|
29 |
+
editing_prompt=['male person', 'female person'], # Concepts to apply
|
30 |
+
reverse_editing_direction=[True, False], # Direction of guidance i.e. decrease the first and increase the second concept
|
31 |
+
edit_warmup_steps=[10, 10], # Warmup period for each concept
|
32 |
+
edit_guidance_scale=[4, 4], # Guidance scale for each concept
|
33 |
+
edit_threshold=[0.95, 0.95], # 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
|
34 |
+
edit_momentum_scale=0.3, # Momentum scale that will be added to the latent guidance
|
35 |
+
edit_mom_beta=0.6, # Momentum beta
|
36 |
+
edit_weights=[1, 1] # Weights of the individual concepts against each other
|
37 |
+
)
|
38 |
+
|
39 |
+
images_edited = out_edit.images[0]
|
40 |
+
|
41 |
+
return [
|
42 |
+
(images, 'Stable Diffusion'),
|
43 |
+
(images_edited, 'Fair Diffusion')
|
44 |
+
]
|
45 |
|
46 |
+
inputs = [
|
47 |
+
gr.inputs.Textbox(label='Prompt'),
|
48 |
+
gr.inputs.Number(label='Seed', default=0, step=1)
|
49 |
+
]
|
50 |
|
51 |
+
outputs = gr.outputs.Image(label='Images', type='numpy', number=2)
|
|
|
52 |
|
53 |
+
title = 'Semantic Edit Pipeline'
|
54 |
+
description = 'Semantic Edit Pipeline implementation using SemDiffusers.'
|
55 |
+
article = "<h3 style='text-align: center'><a href='https://github.com/crowsonkb/semdiffusers'>SemDiffusers</a></h3>"
|
56 |
|
57 |
+
gr.Interface(
|
58 |
+
infer,
|
59 |
+
inputs,
|
60 |
+
outputs,
|
61 |
+
title=title,
|
62 |
+
description=description,
|
63 |
+
article=article,
|
64 |
+
theme='compact'
|
65 |
+
).launch();
|
|
|
|
|
|
|
|
|
|
|
|