Spaces:
Sleeping
Sleeping
minhwan
commited on
Commit
·
4992ddf
1
Parent(s):
3b04947
Add application file
Browse files- app.py +165 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
|
7 |
+
st.set_page_config(page_title="Image Processing MVP", layout="wide")
|
8 |
+
st.title("Image Processing MVP")
|
9 |
+
st.markdown("When you upload your image, our protective filter will be applied to ensure it is not used as training data for deepfake purposes")
|
10 |
+
st.markdown("Please, no refresh")
|
11 |
+
st.markdown(
|
12 |
+
"""
|
13 |
+
<style>
|
14 |
+
.stFileUploader label {
|
15 |
+
font-size: 20px;
|
16 |
+
font-weight: 500;
|
17 |
+
color: #1f77b4;
|
18 |
+
}
|
19 |
+
.stRadio label {
|
20 |
+
font-size: 20px;
|
21 |
+
font-weight: 500;
|
22 |
+
color: #1f77b4;
|
23 |
+
}
|
24 |
+
.stRadio div {
|
25 |
+
display: flex;
|
26 |
+
gap: 20px;
|
27 |
+
}
|
28 |
+
.custom-caption-1 {
|
29 |
+
font-size: 36px;
|
30 |
+
font-weight: bold;
|
31 |
+
text-align: center;
|
32 |
+
margin-top: 10px;
|
33 |
+
padding: 0 0 200px 0;
|
34 |
+
}
|
35 |
+
.custom-caption-2 {
|
36 |
+
font-size: 36px;
|
37 |
+
font-weight: bold;
|
38 |
+
text-align: center;
|
39 |
+
margin-top: 10px;
|
40 |
+
padding: 0 0 30px 0;
|
41 |
+
}
|
42 |
+
.button-container {
|
43 |
+
text-align: center;
|
44 |
+
margin-top: 30px;
|
45 |
+
}
|
46 |
+
.stButton button {
|
47 |
+
width: 50%;
|
48 |
+
font-size: 25px;
|
49 |
+
padding: 10px 20px;
|
50 |
+
background-color: #FFFFFF;
|
51 |
+
font-weight: bold;
|
52 |
+
color: black;
|
53 |
+
opacity: 0.8;
|
54 |
+
border: 3px solid black;
|
55 |
+
border-radius: 5px;
|
56 |
+
cursor: pointer;
|
57 |
+
margin: 0 auto 50px auto;
|
58 |
+
display: block;
|
59 |
+
}
|
60 |
+
.stButton button:hover {
|
61 |
+
background-color: #FFFFFF;
|
62 |
+
border: 3px solid #FF0080;
|
63 |
+
color: #FF0080;
|
64 |
+
opacity: 1;
|
65 |
+
}
|
66 |
+
.survey {
|
67 |
+
text-align: center;
|
68 |
+
margin-top: 10px
|
69 |
+
}
|
70 |
+
.survey-1 {
|
71 |
+
font-size: 25px;
|
72 |
+
text-align: center;
|
73 |
+
margin-top: 10px
|
74 |
+
font-weight: bold;
|
75 |
+
}
|
76 |
+
.survey-2 {
|
77 |
+
text-align: center;
|
78 |
+
margin-top: 10px
|
79 |
+
font-weight: bold;
|
80 |
+
padding 0 auto 50px auto
|
81 |
+
}
|
82 |
+
.a-tag {
|
83 |
+
color: #FF0080;
|
84 |
+
text-decoration: none;
|
85 |
+
}
|
86 |
+
a:hover {
|
87 |
+
color: #FF0080;
|
88 |
+
text-decoration: none;
|
89 |
+
}
|
90 |
+
</style>
|
91 |
+
""",
|
92 |
+
unsafe_allow_html=True,
|
93 |
+
)
|
94 |
+
|
95 |
+
|
96 |
+
def change_hair_to_blonde(image):
|
97 |
+
# Convert to OpenCV format
|
98 |
+
image = np.array(image)
|
99 |
+
# Convert the image to HSV color space
|
100 |
+
hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
|
101 |
+
|
102 |
+
# Define the range for hair color (dark colors)
|
103 |
+
lower_hair = np.array([0, 0, 0])
|
104 |
+
upper_hair = np.array([180, 255, 30])
|
105 |
+
|
106 |
+
# Create a mask for hair
|
107 |
+
mask = cv2.inRange(hsv, lower_hair, upper_hair)
|
108 |
+
|
109 |
+
# Change hair color to blonde (light yellow)
|
110 |
+
hsv[mask > 0] = (30, 255, 200)
|
111 |
+
|
112 |
+
# Convert back to RGB color space
|
113 |
+
image_blonde = cv2.cvtColor(hsv, cv2.COLOR_HSV2RGB)
|
114 |
+
return image_blonde
|
115 |
+
|
116 |
+
def add_noise(image):
|
117 |
+
# Convert to OpenCV format
|
118 |
+
image_np = np.array(image)
|
119 |
+
# Generate random noise
|
120 |
+
noise = np.random.normal(0, 25, image_np.shape).astype(np.uint8)
|
121 |
+
# Add noise to the image
|
122 |
+
noisy_image = cv2.add(image_np, noise)
|
123 |
+
return noisy_image
|
124 |
+
|
125 |
+
|
126 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
|
127 |
+
|
128 |
+
if uploaded_file is not None:
|
129 |
+
image = Image.open(uploaded_file)
|
130 |
+
|
131 |
+
st.write("Processing...")
|
132 |
+
|
133 |
+
# Save the original image as a numpy array
|
134 |
+
image_np = np.array(image)
|
135 |
+
|
136 |
+
col1, col2 = st.columns(2)
|
137 |
+
|
138 |
+
with col1:
|
139 |
+
st.image(image, use_column_width=True)
|
140 |
+
st.markdown('<div class="custom-caption-1">Upload Image</div>', unsafe_allow_html=True)
|
141 |
+
|
142 |
+
with col2:
|
143 |
+
st.image(image, use_column_width=True)
|
144 |
+
st.markdown('<div class="custom-caption-1">Processed Image</div>', unsafe_allow_html=True)
|
145 |
+
|
146 |
+
|
147 |
+
|
148 |
+
|
149 |
+
button_clicked = st.button("Put Upper Pictures into Deepfake Model")
|
150 |
+
st.markdown('<p class="survey">If you have used this feature or curious about our technical principles, we would appreciate it if you could respond to the survey below.</p>', unsafe_allow_html=True)
|
151 |
+
st.markdown('<p class="survey-1"><a href="https://docs.google.com/forms/d/e/1FAIpQLSdzRtuvQyp3CQDhlxEag40v2yDM7u9NYpJ2gv5kgwuNbo1gUA/viewform?usp=sf_link" target="_blank" class="a-tag">Participate in this Survey would help us!!</a></p>', unsafe_allow_html=True)
|
152 |
+
st.markdown('<p class="survey-2">Thank you for using our service!!</p>', unsafe_allow_html=True)
|
153 |
+
|
154 |
+
if button_clicked:
|
155 |
+
with col1:
|
156 |
+
processed_image = change_hair_to_blonde(image)
|
157 |
+
st.image(processed_image, use_column_width=True)
|
158 |
+
st.markdown('<div class="custom-caption-2">Upload Image Deepfake Output</div>', unsafe_allow_html=True)
|
159 |
+
|
160 |
+
with col2:
|
161 |
+
deepfake_image = add_noise(image)
|
162 |
+
st.image(deepfake_image, use_column_width=True)
|
163 |
+
st.markdown('<div class="custom-caption-2">Processed Image Deepfake Output</div>', unsafe_allow_html=True)
|
164 |
+
|
165 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
opencv-python
|
3 |
+
numpy
|