Spaces:
Runtime error
Runtime error
update
Browse files
app.py
CHANGED
@@ -1,22 +1,53 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from huggingface_hub import create_discussion
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
token =
|
6 |
repo = "Team8/dataset"
|
7 |
|
8 |
# <p style="text-align: center; color: black;"> π¨ <span style='color: #6d071a;'>FindMy</span>Art</p>
|
9 |
-
description = """# <p style="text-align: center; color: black;"> π¨ <span style='color: #6d071a;'>
|
10 |
<span>This is a space to opt-out your images from datasets. After you check that your image is in the dataset,
|
11 |
fill an explanation for why you want it to be removed and specify if you want to encrypt the issue that will be opened on the dataset,
|
12 |
by checking the Encrypt box.</span>"""
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
def open_issue(explanation, email, encrypt):
|
|
|
|
|
|
|
|
|
15 |
create_discussion(
|
16 |
repo_id=repo,
|
17 |
repo_type="dataset",
|
18 |
title="[OPT-OUT REQUEST] Remove image from the dataset",
|
19 |
-
description=explanation
|
20 |
token = token,
|
21 |
)
|
22 |
# to do add issue id to the link
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from huggingface_hub import create_discussion
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
+
from Crypto.PublicKey import RSA
|
6 |
+
from Crypto.Random import get_random_bytes
|
7 |
+
from Crypto.Cipher import AES, PKCS1_OAEP
|
8 |
+
import base64
|
9 |
|
10 |
+
token = os.environ["CLAIM"]
|
11 |
repo = "Team8/dataset"
|
12 |
|
13 |
# <p style="text-align: center; color: black;"> π¨ <span style='color: #6d071a;'>FindMy</span>Art</p>
|
14 |
+
description = """# <p style="text-align: center; color: black;"> π¨ <span style='color: #6d071a;'>RemoveMy</span>Art</p>
|
15 |
<span>This is a space to opt-out your images from datasets. After you check that your image is in the dataset,
|
16 |
fill an explanation for why you want it to be removed and specify if you want to encrypt the issue that will be opened on the dataset,
|
17 |
by checking the Encrypt box.</span>"""
|
18 |
|
19 |
+
|
20 |
+
def encrypt_text(data):
|
21 |
+
loc = hf_hub_download(repo_id="Team8/dataset", repo_type="dataset", filename="receiver.pem")
|
22 |
+
data = data.encode("utf-8")
|
23 |
+
file_out = open("encrypted_data.bin", "wb")
|
24 |
+
|
25 |
+
recipient_key = RSA.import_key(open(loc).read())
|
26 |
+
session_key = get_random_bytes(16)
|
27 |
+
|
28 |
+
# Encrypt the session key with the public RSA key
|
29 |
+
cipher_rsa = PKCS1_OAEP.new(recipient_key)
|
30 |
+
enc_session_key = cipher_rsa.encrypt(session_key)
|
31 |
+
|
32 |
+
# Encrypt the data with the AES session key
|
33 |
+
cipher_aes = AES.new(session_key, AES.MODE_EAX)
|
34 |
+
ciphertext, tag = cipher_aes.encrypt_and_digest(data)
|
35 |
+
[ file_out.write(x) for x in (enc_session_key, cipher_aes.nonce, tag, ciphertext) ]
|
36 |
+
file_out.close()
|
37 |
+
with open("encrypted_data.bin", "rb") as image_file:
|
38 |
+
encoded_string = base64.b64encode(image_file.read())
|
39 |
+
return encoded_string
|
40 |
+
|
41 |
def open_issue(explanation, email, encrypt):
|
42 |
+
if encrypt:
|
43 |
+
data = explanation + "\n User email: " + email
|
44 |
+
explanation = f"Encrypted\n{encrypt_text(data)}"
|
45 |
+
|
46 |
create_discussion(
|
47 |
repo_id=repo,
|
48 |
repo_type="dataset",
|
49 |
title="[OPT-OUT REQUEST] Remove image from the dataset",
|
50 |
+
description=explanation,
|
51 |
token = token,
|
52 |
)
|
53 |
# to do add issue id to the link
|