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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def change_hair_to_blonde(image):
|
| 7 |
# Convert to OpenCV format
|
|
@@ -23,45 +201,68 @@ def change_hair_to_blonde(image):
|
|
| 23 |
image_blonde = cv2.cvtColor(hsv, cv2.COLOR_HSV2RGB)
|
| 24 |
return image_blonde
|
| 25 |
|
| 26 |
-
def
|
| 27 |
# Convert to OpenCV format
|
| 28 |
image_np = np.array(image)
|
| 29 |
-
# Generate random
|
| 30 |
-
noise = np.random.
|
| 31 |
-
#
|
| 32 |
-
noisy_image = cv2.
|
| 33 |
return noisy_image
|
| 34 |
|
| 35 |
-
def
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
uploaded_file = st.file_uploader("μ΄λ―Έμ§λ₯Ό
|
| 48 |
|
| 49 |
if uploaded_file is not None:
|
| 50 |
image = Image.open(uploaded_file)
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
st.write("μ²λ¦¬ μ€...")
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import streamlit.components.v1 as components
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
| 5 |
+
from PIL import Image, ExifTags
|
| 6 |
+
|
| 7 |
+
# κ°μ₯ λ¨Όμ set_page_config() νΈμΆ
|
| 8 |
+
st.set_page_config(page_title="λ₯νμ΄ν¬ μ¬μ λ°©μ§ νν°(ν
μ€νΈ)", layout="wide")
|
| 9 |
+
|
| 10 |
+
ga_code = """
|
| 11 |
+
<!-- Global site tag (gtag.js) - Google Analytics -->
|
| 12 |
+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-PZPBGNENQG"></script>
|
| 13 |
+
<script>
|
| 14 |
+
window.dataLayer = window.dataLayer || [];
|
| 15 |
+
function gtag(){dataLayer.push(arguments);}
|
| 16 |
+
gtag('js', new Date());
|
| 17 |
+
gtag('config', 'G-PZPBGNENQG');
|
| 18 |
+
</script>
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
# Streamlitμ GA μ½λ μ½μ
|
| 22 |
+
components.html(ga_code, height=0)
|
| 23 |
+
|
| 24 |
+
# λ°μν λμμΈμ μν CSS
|
| 25 |
+
css = """
|
| 26 |
+
<style>
|
| 27 |
+
/* κ³΅ν΅ μ€νμΌ */
|
| 28 |
+
.stFileUploader label,
|
| 29 |
+
.stRadio label,
|
| 30 |
+
.stButton button,
|
| 31 |
+
.survey-1 {
|
| 32 |
+
transition: all 0.3s ease;
|
| 33 |
+
}
|
| 34 |
+
.stFileUploader label {
|
| 35 |
+
font-size: 20px;
|
| 36 |
+
font-weight: 500;
|
| 37 |
+
color: #1f77b4;
|
| 38 |
+
}
|
| 39 |
+
.stRadio label {
|
| 40 |
+
font-size: 20px;
|
| 41 |
+
font-weight: 500;
|
| 42 |
+
color: #1f77b4;
|
| 43 |
+
}
|
| 44 |
+
.stRadio div {
|
| 45 |
+
display: flex;
|
| 46 |
+
gap: 20px;
|
| 47 |
+
}
|
| 48 |
+
.custom-caption-1 {
|
| 49 |
+
font-size: 36px;
|
| 50 |
+
font-weight: bold;
|
| 51 |
+
text-align: center;
|
| 52 |
+
margin-top: 10px;
|
| 53 |
+
padding: 0 0 20px 0;
|
| 54 |
+
}
|
| 55 |
+
.custom-caption-2 {
|
| 56 |
+
font-size: 36px;
|
| 57 |
+
font-weight: bold;
|
| 58 |
+
text-align: center;
|
| 59 |
+
margin-top: 10px;
|
| 60 |
+
padding: 0 0 30px 0;
|
| 61 |
+
}
|
| 62 |
+
.button-container {
|
| 63 |
+
text-align: center;
|
| 64 |
+
margin-top: 30px;
|
| 65 |
+
}
|
| 66 |
+
.stButton button {
|
| 67 |
+
width: 50%;
|
| 68 |
+
font-size: 25px;
|
| 69 |
+
padding: 10px 20px;
|
| 70 |
+
background-color: #FFFFFF;
|
| 71 |
+
font-weight: bold;
|
| 72 |
+
color: black;
|
| 73 |
+
opacity: 0.8;
|
| 74 |
+
border: 3px solid black;
|
| 75 |
+
border-radius: 5px;
|
| 76 |
+
cursor: pointer;
|
| 77 |
+
margin: 0 auto 50px auto;
|
| 78 |
+
display: block;
|
| 79 |
+
}
|
| 80 |
+
.stButton button:hover {
|
| 81 |
+
background-color: #FFFFFF;
|
| 82 |
+
border: 3px solid #FF0080;
|
| 83 |
+
color: #FF0080;
|
| 84 |
+
opacity: 1;
|
| 85 |
+
}
|
| 86 |
+
.survey {
|
| 87 |
+
text-align: center;
|
| 88 |
+
margin-top: 10px
|
| 89 |
+
}
|
| 90 |
+
.survey-1 {
|
| 91 |
+
font-size: 25px;
|
| 92 |
+
text-align: center;
|
| 93 |
+
margin-top: 10px;
|
| 94 |
+
font-weight: bold;
|
| 95 |
+
}
|
| 96 |
+
.survey-2 {
|
| 97 |
+
text-align: center;
|
| 98 |
+
margin-top: 10px;
|
| 99 |
+
font-weight: bold;
|
| 100 |
+
padding: 0 auto 50px auto;
|
| 101 |
+
}
|
| 102 |
+
.a-tag {
|
| 103 |
+
color: #FF0080;
|
| 104 |
+
text-decoration: none;
|
| 105 |
+
}
|
| 106 |
+
a:hover {
|
| 107 |
+
color: #FF0080;
|
| 108 |
+
text-decoration: none;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
/* μ€λ§νΈν° νλ©΄ μ€νμΌ */
|
| 112 |
+
@media only screen and (max-width: 600px) {
|
| 113 |
+
.stFileUploader label,
|
| 114 |
+
.stRadio label,
|
| 115 |
+
.stButton button,
|
| 116 |
+
.survey-1 {
|
| 117 |
+
font-size: 16px;
|
| 118 |
+
}
|
| 119 |
+
.custom-caption-1,
|
| 120 |
+
.custom-caption-2 {
|
| 121 |
+
font-size: 24px;
|
| 122 |
+
padding: 0 0 20px 0;
|
| 123 |
+
}
|
| 124 |
+
.stButton button {
|
| 125 |
+
width: 100%;
|
| 126 |
+
font-size: 18px;
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/* νλΈλ¦Ώ νλ©΄ μ€νμΌ */
|
| 131 |
+
@media only screen and (min-width: 601px) and (max-width: 1024px) {
|
| 132 |
+
.stFileUploader label,
|
| 133 |
+
.stRadio label,
|
| 134 |
+
.stButton button,
|
| 135 |
+
.survey-1 {
|
| 136 |
+
font-size: 18px;
|
| 137 |
+
}
|
| 138 |
+
.custom-caption-1,
|
| 139 |
+
.custom-caption-2 {
|
| 140 |
+
font-size: 28px;
|
| 141 |
+
padding: 0 0 40px 0;
|
| 142 |
+
}
|
| 143 |
+
.stButton button {
|
| 144 |
+
width: 75%;
|
| 145 |
+
font-size: 20px;
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
/* λ°μ€ν¬ν± νλ©΄ μ€νμΌ */
|
| 150 |
+
@media only screen and (min-width: 1025px) {
|
| 151 |
+
.stFileUploader label,
|
| 152 |
+
.stRadio label,
|
| 153 |
+
.stButton button,
|
| 154 |
+
.survey-1 {
|
| 155 |
+
font-size: 20px;
|
| 156 |
+
}
|
| 157 |
+
.custom-caption-1,
|
| 158 |
+
.custom-caption-2 {
|
| 159 |
+
font-size: 36px;
|
| 160 |
+
padding: 0 0 200px 0;
|
| 161 |
+
}
|
| 162 |
+
.stButton button {
|
| 163 |
+
width: 50%;
|
| 164 |
+
font-size: 25px;
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
</style>
|
| 168 |
+
"""
|
| 169 |
+
|
| 170 |
+
# CSSλ₯Ό HTMLλ‘ μ½μ
|
| 171 |
+
st.markdown(css, unsafe_allow_html=True)
|
| 172 |
+
|
| 173 |
+
st.title("λ₯νμ΄ν¬ μ¬μ λ°©μ§ νν°(ν
μ€νΈ)")
|
| 174 |
+
st.markdown("")
|
| 175 |
+
st.markdown("<span style='font-size: 18px;'>μλ
νμΈμ! μ ν¬λ λ₯νμ΄ν¬λ‘λΆν° μ¬λ¬λΆμ μ¬μ§μ 보νΈνλ μ루μ
μ κ°λ°νκ³ μμ΅λλ€.</span>", unsafe_allow_html=True)
|
| 176 |
+
st.markdown("<span style='font-size: 18px;'>μ ν¬μ λͺ©νλ μ¨λΌμΈμ κ²μλ κ°μΈμ μ¬μ§μ΄ μ
μ± λ₯νμ΄ν¬ μμμ μ¬μ©λμ§ μλλ‘ νλ κ²μ
λλ€. νμ¬λ κ°λ°μ λ§λ¬΄λ¦¬νκ³ μλΉμ€ν νκΈ° μ , μ¬λ¬λΆμ μ견μ λ£κΈ° μν΄ κ°λ¨ν ν
μ€νΈλ₯Ό μ§ννκ³ μμ΅λλ€.</span>", unsafe_allow_html=True)
|
| 177 |
+
st.markdown("<span style='font-size: 18px;'>μ΅κ·Ό SNSμ μ
λ‘λλ μ΄λ―Έμ§κ° λ₯νμ΄ν¬ ν¬λ₯΄λ
Έλ¬Όμ μ
μ©λλ μ¬λ‘κ° λ§€μΌ λ³΄κ³ λκ³ μμ΅λλ€. λ°λΌμ ν΄κ²°μ±
μ κ°κ΅¬νκΈ° μν΄, μ¬λ¬λΆμ μμ€ν μκ²¬μ΄ νμν©λλ€.</span>", unsafe_allow_html=True)
|
| 178 |
+
st.markdown("<span style='font-size: 18px;'>μλ λ§ν¬λ₯Ό ν΅ν΄ μ ν¬ μλΉμ€λ₯Ό μ΄μ©ν΄ 보μ ν, μΈν°λ·°μ μ°Έμ¬ν΄ μ£Όμλ©΄ ν° λμμ΄ λκ² μ΅λλ€. μ¬λ¬λΆμ νΌλλ°±μ μλΉμ€ κ°μ μ κ·μ€ν μλ£κ° λ κ²μ
λλ€.</span>", unsafe_allow_html=True)
|
| 179 |
+
st.markdown("")
|
| 180 |
+
st.markdown("<span style='font-size: 18px;'>λμ μ리 : 1. μ΄λ―Έμ§λ₯Ό μ
λ‘λνλ©΄, μ¬μ λ°©μ§ νν°κ° μ μ©λ μ΄λ―Έμ§λ₯Ό 보μ¬λ립λλ€. 2. νλ¨μ ν° λ²νΌμ ν΄λ¦νλ©΄ λ₯νμ΄ν¬ λͺ¨λΈμ ν΅ν΄ μμ±λ κ²°κ³Όλ₯Ό νμΈν μ μμ΅λλ€.</span>", unsafe_allow_html=True)
|
| 181 |
+
st.markdown("<span style='font-size: 18px;'>μ¬λ¬λΆμ μ°Έμ¬μ κ°μ¬λ립λλ€!</span>", unsafe_allow_html=True)
|
| 182 |
+
st.markdown("<span style='font-size: 14px;'> *μ¬μ λ°©μ§ νν°λ: μ¬λ¬λΆμ μ¬μ§μ΄ λ₯νμ΄ν¬ λͺ¨λΈμ νμ΅λμ§ λͺ»νλλ‘ λ°©ν΄νλ λ
Έμ΄μ¦(noise)ννμ νν°.</span>", unsafe_allow_html=True)
|
| 183 |
|
| 184 |
def change_hair_to_blonde(image):
|
| 185 |
# Convert to OpenCV format
|
|
|
|
| 201 |
image_blonde = cv2.cvtColor(hsv, cv2.COLOR_HSV2RGB)
|
| 202 |
return image_blonde
|
| 203 |
|
| 204 |
+
def add_noise(image):
|
| 205 |
# Convert to OpenCV format
|
| 206 |
image_np = np.array(image)
|
| 207 |
+
# Generate random noise
|
| 208 |
+
noise = np.random.normal(0, 25, image_np.shape).astype(np.uint8)
|
| 209 |
+
# Add noise to the image
|
| 210 |
+
noisy_image = cv2.add(image_np, noise)
|
| 211 |
return noisy_image
|
| 212 |
|
| 213 |
+
def correct_image_orientation(image):
|
| 214 |
+
try:
|
| 215 |
+
for orientation in ExifTags.TAGS.keys():
|
| 216 |
+
if ExifTags.TAGS[orientation] == 'Orientation':
|
| 217 |
+
break
|
| 218 |
+
exif = image._getexif()
|
| 219 |
+
if exif is not None:
|
| 220 |
+
orientation = exif.get(orientation, 1)
|
| 221 |
+
if orientation == 3:
|
| 222 |
+
image = image.rotate(180, expand=True)
|
| 223 |
+
elif orientation == 6:
|
| 224 |
+
image = image.rotate(270, expand=True)
|
| 225 |
+
elif orientation == 8:
|
| 226 |
+
image = image.rotate(90, expand=True)
|
| 227 |
+
except (AttributeError, KeyError, IndexError):
|
| 228 |
+
pass
|
| 229 |
+
return image
|
| 230 |
|
| 231 |
+
uploaded_file = st.file_uploader("μ΄λ―Έμ§λ₯Ό μ
λ‘λνμΈμ...", type=["jpg", "png", "jpeg"])
|
| 232 |
|
| 233 |
if uploaded_file is not None:
|
| 234 |
image = Image.open(uploaded_file)
|
| 235 |
+
image = correct_image_orientation(image)
|
| 236 |
+
|
| 237 |
+
st.write("μ΄λ―Έμ§ μ²λ¦¬ μ€...")
|
| 238 |
+
|
| 239 |
+
# Save the original image as a numpy array
|
| 240 |
+
image_np = np.array(image)
|
| 241 |
+
|
| 242 |
+
col1, col2 = st.columns(2)
|
| 243 |
+
|
| 244 |
+
with col1:
|
| 245 |
+
st.image(image, use_column_width=True)
|
| 246 |
+
st.markdown('<div class="custom-caption-1">μ
λ‘λν μ΄λ―Έμ§</div>', unsafe_allow_html=True)
|
| 247 |
+
|
| 248 |
+
with col2:
|
| 249 |
+
st.image(image, use_column_width=True)
|
| 250 |
+
st.markdown('<div class="custom-caption-1">νν°λ₯Ό μ
ν μ΄λ―Έμ§</div>', unsafe_allow_html=True)
|
| 251 |
+
|
| 252 |
+
button_clicked = st.button("μλ¨μ λ μ¬μ§μ λ₯νμ΄ν¬ λͺ¨λΈμ νμ΅μν€κΈ°")
|
| 253 |
+
st.markdown('<p class="survey">μ μλΉμ€λ₯Ό μ¬μ©ν΄ 보μ
¨κ±°λ, μ ν¬ κΈ°μ μ μ리μ κ΄μ¬μ΄ μμΌμ λΆλ€κ»μ μλμ κ°λ¨ν μΈν°λ·°μ μ°Έμ¬ν΄ μ£Όμλ©΄ μ§μ¬μΌλ‘ κ°μ¬λλ¦¬κ² μ΅λλ€.</p>', unsafe_allow_html=True)
|
| 254 |
+
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">μ¬κΈ°λ₯Ό ν΄οΏ½οΏ½οΏ½νμ¬ μΈν°λ·°μ μν΄ μ£Όμ λ€λ©΄ ν° λμμ΄ λ κ² κ°μ΅λλ€!!</a></p>', unsafe_allow_html=True)
|
| 255 |
+
st.markdown('<p class="survey-2">μλΉμ€λ₯Ό μ΄μ©ν΄ μ£Όμ
μ κ°μ¬ν©λλ€! μ’μ ν루 보λ΄μΈμ!</p>', unsafe_allow_html=True)
|
| 256 |
+
|
| 257 |
+
if button_clicked:
|
| 258 |
+
with col1:
|
| 259 |
+
processed_image = change_hair_to_blonde(image)
|
| 260 |
+
st.image(processed_image, use_column_width=True)
|
| 261 |
+
st.markdown('<div class="custom-caption-2">μλ³Έ μ΄λ―Έμ§λ₯Ό λ₯νμ΄ν¬ λͺ¨λΈμ λ£μμ κ²½μ°</div>', unsafe_allow_html=True)
|
| 262 |
+
st.markdown("<span>μ΄ν΄λ₯Ό λκΈ° μν΄ μ¬μ§μ λ
Έλμμ μ
νλ λ₯νμ΄ν¬ μκ³ λ¦¬μ¦ μ μ©. μλ³Έ μ΄λ―Έμ§λ λ₯νμ΄ν¬ μκ³ λ¦¬μ¦μ μν₯μ λ°μ.</span>", unsafe_allow_html=True)
|
| 263 |
+
|
| 264 |
+
with col2:
|
| 265 |
+
deepfake_image = add_noise(image)
|
| 266 |
+
st.image(deepfake_image, use_column_width=True)
|
| 267 |
+
st.markdown('<div class="custom-caption-2">μ¬μ λ°©μ§ νν° μ΄λ―Έμ§λ₯Ό λ₯νμ΄ν¬ λͺ¨λΈμ λ£μμ κ²½μ°</div>', unsafe_allow_html=True)
|
| 268 |
+
st.markdown("<span>μ¬μ λ°©μ§ νν°λ₯Ό μ
ν μ΄λ―Έμ§λ λ₯νμ΄ν¬ μκ³ λ¦¬μ¦μ μν₯μ λ°μ§ μκ³ λ
Έμ΄μ¦ μ²λ¦¬κ° λμ΄ μμ보기 νλ μ¬μ§μ μΆλ ₯. μ¦, λ₯νμ΄ν¬ μ¬μ§ ν©μ±μ λ°©ν΄ν¨.</span>", unsafe_allow_html=True)
|