Update app.py
Browse files
app.py
CHANGED
@@ -11,10 +11,51 @@ from roop.processors.frame.core import get_frame_processors_modules
|
|
11 |
from roop.utilities import normalize_output_path
|
12 |
import os
|
13 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
source_path = "input.jpg"
|
19 |
target_path = "target.jpg"
|
20 |
|
@@ -63,30 +104,12 @@ def swap_face(source_file, target_file, doFaceEnhancer):
|
|
63 |
start()
|
64 |
return output_path
|
65 |
|
66 |
-
|
67 |
-
html_section_1 = "<div><h1>Welcome to the Face Swap App</h1></div>"
|
68 |
-
html_section_2 = "<div><p>Upload your source and target images to swap faces. Optionally, use the face enhancer feature.</p></div>"
|
69 |
-
html_section_3 = """<div>
|
70 |
-
<a href="https://ziverr.xyz/monica" target="_blank" style="display: inline-block;">
|
71 |
-
<img decoding="async" alt="banner" src="https://ziverr.xyz/wp-content/uploads/2024/06/PASSIVE-3.gif">
|
72 |
-
</a>
|
73 |
-
<a href="https://go.fiverr.com/visit/?bta=36184&brand=fiverrcpa&landingPage=https%253A%252F%252Fwww.fiverr.com%252Fcategories%252Fprogramming-tech%252Fai-coding%252Fai-applications%253Fsource%253Dcategory_tree" target="_blank" style="display: inline-block;">
|
74 |
-
<img fetchpriority="high" decoding="async" width="468" height="120" src="https://ziverr.xyz/wp-content/uploads/2024/06/PASSIVE-1.gif" class="attachment-large size-large wp-image-1266" alt="">
|
75 |
-
</a>
|
76 |
-
<a href="https://beta.publishers.adsterra.com/referral/UNXJYTziBP" target="_blank" style="display: inline-block;">
|
77 |
-
<img decoding="async" alt="banner" src="https://landings-cdn.adsterratech.com/referralBanners/gif/468x120_adsterra_reff.gif">
|
78 |
-
</a>
|
79 |
-
</div>"""
|
80 |
-
|
81 |
app = gr.Blocks()
|
82 |
|
83 |
with app:
|
84 |
-
gr.HTML(html_section_1)
|
85 |
-
gr.HTML(html_section_2)
|
86 |
-
gr.HTML(html_section_3)
|
87 |
gr.Interface(
|
88 |
fn=swap_face,
|
89 |
-
inputs=[gr.Image(), gr.Image(), gr.Checkbox(label="face_enhancer?", info="do face enhancer?")],
|
90 |
outputs="image"
|
91 |
)
|
92 |
|
|
|
11 |
from roop.utilities import normalize_output_path
|
12 |
import os
|
13 |
from PIL import Image
|
14 |
+
from cryptography.hazmat.primitives.asymmetric import rsa, padding
|
15 |
+
from cryptography.hazmat.primitives import serialization, hashes
|
16 |
+
from cryptography.hazmat.backends import default_backend
|
17 |
+
from cryptography.hazmat.primitives.asymmetric import utils
|
18 |
+
import base64
|
19 |
+
import json
|
20 |
+
import datetime
|
21 |
|
22 |
+
def load_public_key_from_file(file_path):
|
23 |
+
with open(file_path, "rb") as key_file:
|
24 |
+
public_key = serialization.load_pem_public_key(
|
25 |
+
key_file.read(),
|
26 |
+
backend=default_backend()
|
27 |
+
)
|
28 |
+
return public_key
|
29 |
|
30 |
+
def verify_signature(public_key, data, signature):
|
31 |
+
"""
|
32 |
+
Verify a signature with a public key.
|
33 |
+
"""
|
34 |
+
try:
|
35 |
+
public_key.verify(
|
36 |
+
signature,
|
37 |
+
data,
|
38 |
+
padding.PSS(
|
39 |
+
mgf=padding.MGF1(hashes.SHA256()),
|
40 |
+
salt_length=padding.PSS.MAX_LENGTH
|
41 |
+
),
|
42 |
+
hashes.SHA256()
|
43 |
+
)
|
44 |
+
return True
|
45 |
+
except Exception as e:
|
46 |
+
print("Verification failed:", e)
|
47 |
+
raise Exception("Verification failed:%s"%e)
|
48 |
|
49 |
+
public_key = load_public_key_from_file("./nsfwais.pubkey.pem")
|
50 |
+
def swap_face(source_file, target_file, doFaceEnhancer, skey):
|
51 |
+
|
52 |
+
skey = json.loads(base64.b64decode(skey).decode())
|
53 |
+
#first validate skey
|
54 |
+
verify_signature(public_key, skey["t"], skey["s"])
|
55 |
+
timestamp_requested = int(skey["t"])
|
56 |
+
timestamp_now = int(datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).timestamp())
|
57 |
+
if timestamp_now - timestamp_requested > 20:
|
58 |
+
raise Exception(f"authkey timeout, {timestamp_now - timestamp_requested}")
|
59 |
source_path = "input.jpg"
|
60 |
target_path = "target.jpg"
|
61 |
|
|
|
104 |
start()
|
105 |
return output_path
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
app = gr.Blocks()
|
108 |
|
109 |
with app:
|
|
|
|
|
|
|
110 |
gr.Interface(
|
111 |
fn=swap_face,
|
112 |
+
inputs=[gr.Image(visible=False), gr.Image(visible=False), gr.Checkbox(label="face_enhancer?", info="do face enhancer?"), gr.TextBox(visible=False)],
|
113 |
outputs="image"
|
114 |
)
|
115 |
|