Files changed (1) hide show
  1. app.py +58 -31
app.py CHANGED
@@ -1,38 +1,65 @@
1
- import streamlit as st
2
- import process
3
- import pandas as pd
4
 
5
- st.set_page_config(page_title="Data Anonymizer App")
6
 
7
- st.title("Data Anonymizer App")
 
 
8
 
9
- st.sidebar.title("Data Upload")
10
- uploaded_file = st.sidebar.file_uploader("Choose a CSV file", type="csv")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- if uploaded_file:
13
- df = pd.read_csv(uploaded_file)
14
- st.write("Original Data:")
15
- st.write(df)
16
 
17
- # process the data
18
- processed_df, sensitive_cols = process.process_data(df)
19
 
20
- # display processed data
21
- st.write("Processed Data:")
22
- st.write(processed_df)
23
 
24
- # ask for sensitive columns removal
25
- if sensitive_cols:
26
- st.write(f"The following columns contain sensitive data: {', '.join(sensitive_cols)}")
27
- if st.checkbox("Remove sensitive columns"):
28
- processed_df.drop(columns=sensitive_cols, inplace=True)
29
- else:
30
- st.write("Sensitive columns will not be removed.")
31
-
32
- # ask for k-anonymity
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();