Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,33 @@
|
|
| 1 |
|
| 2 |
import gradio as gr
|
| 3 |
from cryptography.fernet import Fernet
|
| 4 |
-
def encrypt():
|
| 5 |
-
|
| 6 |
-
message =
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
# the key or use random key generator
|
| 11 |
-
# here I'm using fernet to generate key
|
| 12 |
-
|
| 13 |
key = Fernet.generate_key()
|
| 14 |
-
|
| 15 |
-
# Instance the Fernet class with the key
|
| 16 |
|
| 17 |
fernet = Fernet(key)
|
| 18 |
-
|
| 19 |
# then use the Fernet class instance
|
| 20 |
# to encrypt the string string must
|
| 21 |
# be encoded to byte string before encryption
|
| 22 |
-
encMessage = fernet.encrypt(
|
| 23 |
|
| 24 |
print("original string: ", message)
|
| 25 |
print("encrypted string: ", encMessage)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
# Fernet instance of the key,
|
| 29 |
-
# that was used for encrypting the string
|
| 30 |
-
# encoded byte string is returned by decrypt method,
|
| 31 |
-
# so decode it to string with decode methods
|
| 32 |
decMessage = fernet.decrypt(encMessage).decode()
|
| 33 |
|
| 34 |
print("decrypted string: ", decMessage)
|
| 35 |
|
| 36 |
with gr.Blocks() as app:
|
|
|
|
| 37 |
btn = gr.Button()
|
| 38 |
-
btn.click(encrypt,
|
| 39 |
app.launch()
|
| 40 |
|
|
|
|
| 1 |
|
| 2 |
import gradio as gr
|
| 3 |
from cryptography.fernet import Fernet
|
| 4 |
+
def encrypt(message=None,image=None,document=None):
|
| 5 |
+
|
| 6 |
+
if message != None and message != "":
|
| 7 |
+
bytes = message.encode()
|
| 8 |
+
print (bytes)
|
| 9 |
+
|
|
|
|
|
|
|
|
|
|
| 10 |
key = Fernet.generate_key()
|
| 11 |
+
print (f"The Key is: {key}")
|
|
|
|
| 12 |
|
| 13 |
fernet = Fernet(key)
|
| 14 |
+
|
| 15 |
# then use the Fernet class instance
|
| 16 |
# to encrypt the string string must
|
| 17 |
# be encoded to byte string before encryption
|
| 18 |
+
encMessage = fernet.encrypt(bytes)
|
| 19 |
|
| 20 |
print("original string: ", message)
|
| 21 |
print("encrypted string: ", encMessage)
|
| 22 |
|
| 23 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
decMessage = fernet.decrypt(encMessage).decode()
|
| 25 |
|
| 26 |
print("decrypted string: ", decMessage)
|
| 27 |
|
| 28 |
with gr.Blocks() as app:
|
| 29 |
+
mes = gr.Textbox()
|
| 30 |
btn = gr.Button()
|
| 31 |
+
btn.click(encrypt,mes,None)
|
| 32 |
app.launch()
|
| 33 |
|