Omnibus commited on
Commit
7dce7b2
·
1 Parent(s): 539c7c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -19
app.py CHANGED
@@ -1,40 +1,33 @@
1
 
2
  import gradio as gr
3
  from cryptography.fernet import Fernet
4
- def encrypt():
5
- # we will be encrypting the below string.
6
- message = "hello geeks"
7
-
8
- # generate a key for encryption and decryption
9
- # You can use fernet to generate
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(message.encode())
23
 
24
  print("original string: ", message)
25
  print("encrypted string: ", encMessage)
26
 
27
- # decrypt the encrypted string with the
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,None,None)
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