Spaces:
Sleeping
Sleeping
onehowon
commited on
Commit
ยท
83a4e09
1
Parent(s):
ceee1cb
requirement
Browse files
app.py
CHANGED
@@ -7,10 +7,9 @@ from art.attacks.evasion import FastGradientMethod
|
|
7 |
from art.estimators.classification import PyTorchClassifier
|
8 |
from PIL import Image
|
9 |
import numpy as np
|
|
|
10 |
import io
|
11 |
-
import base64
|
12 |
from blind_watermark import WaterMark
|
13 |
-
import matplotlib.pyplot as plt
|
14 |
|
15 |
# Pretrained ResNet50 ๋ชจ๋ธ ๋ถ๋ฌ์ค๊ธฐ (ImageNet ์ฌ์ ํ๋ จ)
|
16 |
model = models.resnet50(pretrained=True)
|
@@ -73,26 +72,37 @@ def generate_adversarial_image(image, eps_value):
|
|
73 |
def apply_watermark(image_pil):
|
74 |
wm_text = "123"
|
75 |
bwm = WaterMark(password_img=123, password_wm=456)
|
76 |
-
|
77 |
-
#
|
78 |
-
|
79 |
-
image_pil.save(
|
80 |
-
|
|
|
|
|
81 |
bwm.read_wm(wm_text, mode='str')
|
82 |
|
83 |
# ์ํฐ๋งํฌ ์ฝ์
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
-
#
|
88 |
def process_image(image, eps_value):
|
89 |
# ์ ๋์ ์ด๋ฏธ์ง ์์ฑ
|
90 |
adv_image = generate_adversarial_image(image, eps_value)
|
91 |
|
92 |
# ์ํฐ๋งํฌ ์ ์ฉ
|
93 |
-
|
94 |
|
95 |
-
return
|
96 |
|
97 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
98 |
gr.Interface(
|
|
|
7 |
from art.estimators.classification import PyTorchClassifier
|
8 |
from PIL import Image
|
9 |
import numpy as np
|
10 |
+
import os
|
11 |
import io
|
|
|
12 |
from blind_watermark import WaterMark
|
|
|
13 |
|
14 |
# Pretrained ResNet50 ๋ชจ๋ธ ๋ถ๋ฌ์ค๊ธฐ (ImageNet ์ฌ์ ํ๋ จ)
|
15 |
model = models.resnet50(pretrained=True)
|
|
|
72 |
def apply_watermark(image_pil):
|
73 |
wm_text = "123"
|
74 |
bwm = WaterMark(password_img=123, password_wm=456)
|
75 |
+
|
76 |
+
# ์ด๋ฏธ์ง ๋ฐ์ดํธ ๋ฐ์ดํฐ๋ฅผ ์์ ํ์ผ๋ก ์ ์ฅ
|
77 |
+
temp_image_path = "temp_image.png"
|
78 |
+
image_pil.save(temp_image_path)
|
79 |
+
|
80 |
+
# temp_image_path ๊ฒฝ๋ก๋ก ์ํฐ๋งํฌ ์ฝ์
์ฒ๋ฆฌ
|
81 |
+
bwm.read_img(temp_image_path)
|
82 |
bwm.read_wm(wm_text, mode='str')
|
83 |
|
84 |
# ์ํฐ๋งํฌ ์ฝ์
|
85 |
+
output_path = "watermarked_image.png"
|
86 |
+
bwm.embed(output_path)
|
87 |
+
|
88 |
+
# ์ฝ์
๋ ์ํฐ๋งํฌ ์ด๋ฏธ์ง ํ์ผ์ ๋ค์ ์ฝ์ด์ PIL ์ด๋ฏธ์ง๋ก ๋ณํ
|
89 |
+
result_image = Image.open(output_path)
|
90 |
+
|
91 |
+
# ์์ ํ์ผ ์ญ์
|
92 |
+
os.remove(temp_image_path)
|
93 |
+
os.remove(output_path)
|
94 |
+
|
95 |
+
return result_image
|
96 |
|
97 |
+
# ์ ์ฒด ์ด๋ฏธ์ง ์ฒ๋ฆฌ ํจ์
|
98 |
def process_image(image, eps_value):
|
99 |
# ์ ๋์ ์ด๋ฏธ์ง ์์ฑ
|
100 |
adv_image = generate_adversarial_image(image, eps_value)
|
101 |
|
102 |
# ์ํฐ๋งํฌ ์ ์ฉ
|
103 |
+
watermarked_image = apply_watermark(adv_image)
|
104 |
|
105 |
+
return watermarked_image
|
106 |
|
107 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
108 |
gr.Interface(
|