Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,10 +45,18 @@ def encrypt(passw=None,mes=None,img=None,doc=None):
|
|
| 45 |
enc_mes = f'{enc_mes}{im_bytes}+bbb+'
|
| 46 |
else:
|
| 47 |
enc_mes = f'{im_bytes}+bbb+'
|
| 48 |
-
print (enc_mes)
|
| 49 |
-
|
| 50 |
-
return enc_mes
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
def decrypt(passw=None,enc_in=None):
|
| 53 |
key = create_key(passw)
|
| 54 |
fernet = Fernet(key)
|
|
@@ -100,7 +108,9 @@ with gr.Blocks() as app:
|
|
| 100 |
with gr.Tab("Encrypt"):
|
| 101 |
pass_in=gr.Textbox(label="Set Password")
|
| 102 |
mes = gr.Textbox(label = "Message")
|
| 103 |
-
|
|
|
|
|
|
|
| 104 |
en_btn = gr.Button("Encrypt")
|
| 105 |
enc_out = gr.Textbox(label="Encrypted Bytes")
|
| 106 |
with gr.Tab("Decrypt"):
|
|
@@ -110,7 +120,7 @@ with gr.Blocks() as app:
|
|
| 110 |
d_txt = gr.Textbox(label="Decrypted")
|
| 111 |
d_im =gr.Image(label="Decrytped Image")
|
| 112 |
d_txt=gr.Textbox()
|
| 113 |
-
en_btn.click(encrypt,[pass_in,mes,im],enc_out)
|
| 114 |
d_btn.click(decrypt,[pass_out,enc_in],[d_im,d_txt])
|
| 115 |
app.launch()
|
| 116 |
|
|
|
|
| 45 |
enc_mes = f'{enc_mes}{im_bytes}+bbb+'
|
| 46 |
else:
|
| 47 |
enc_mes = f'{im_bytes}+bbb+'
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
if doc != None:
|
| 50 |
+
with open(doc, "rb") as file:
|
| 51 |
+
# read all file data
|
| 52 |
+
file_data = file.read()
|
| 53 |
+
enc_doc = fernet.encrypt(file_data)
|
| 54 |
+
enc_file=f'{doc}.ocrpt'
|
| 55 |
+
with open(enc_file, "wb") as file:
|
| 56 |
+
file.write(enc_doc)
|
| 57 |
+
|
| 58 |
+
return enc_mes,enc_file
|
| 59 |
+
|
| 60 |
def decrypt(passw=None,enc_in=None):
|
| 61 |
key = create_key(passw)
|
| 62 |
fernet = Fernet(key)
|
|
|
|
| 108 |
with gr.Tab("Encrypt"):
|
| 109 |
pass_in=gr.Textbox(label="Set Password")
|
| 110 |
mes = gr.Textbox(label = "Message")
|
| 111 |
+
with gr.Row():
|
| 112 |
+
im = gr.Image(type="filepath")
|
| 113 |
+
doc=gr.Files()
|
| 114 |
en_btn = gr.Button("Encrypt")
|
| 115 |
enc_out = gr.Textbox(label="Encrypted Bytes")
|
| 116 |
with gr.Tab("Decrypt"):
|
|
|
|
| 120 |
d_txt = gr.Textbox(label="Decrypted")
|
| 121 |
d_im =gr.Image(label="Decrytped Image")
|
| 122 |
d_txt=gr.Textbox()
|
| 123 |
+
en_btn.click(encrypt,[pass_in,mes,im,doc],enc_out)
|
| 124 |
d_btn.click(decrypt,[pass_out,enc_in],[d_im,d_txt])
|
| 125 |
app.launch()
|
| 126 |
|