RakanAlsheraiwi commited on
Commit
6d2bb07
·
verified ·
1 Parent(s): ccd5cbc

Create App.py

Browse files
Files changed (1) hide show
  1. App.py +39 -0
App.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random
3
+ import string
4
+
5
+ def generate_password(length):
6
+ # Define the character sets
7
+ upper = string.ascii_uppercase
8
+ lower = string.ascii_lowercase
9
+ digits = string.digits
10
+ special = string.punctuation
11
+
12
+ # Ensure the password has at least one of each type
13
+ all_characters = upper + lower + digits + special
14
+ password = [
15
+ random.choice(upper),
16
+ random.choice(lower),
17
+ random.choice(digits),
18
+ random.choice(special)
19
+ ]
20
+
21
+ # Fill the rest of the password length with random characters from the combined set
22
+ password += random.choices(all_characters, k=length-4)
23
+
24
+ # Shuffle the characters to ensure randomness
25
+ random.shuffle(password)
26
+
27
+ # Convert the list to a string and return
28
+ return ''.join(password)
29
+
30
+ # Gradio interface
31
+ interface = gr.Interface(
32
+ fn=generate_password,
33
+ inputs=gr.Slider(8, 32, step=1, default=12, label="Password Length"),
34
+ outputs="text",
35
+ title="Password Generator",
36
+ description="Generate a strong, unique password by selecting the desired length."
37
+ )
38
+
39
+ interface.launch()