File size: 1,124 Bytes
6d2bb07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import gradio as gr
import random
import string

def generate_password(length):
    # Define the character sets
    upper = string.ascii_uppercase
    lower = string.ascii_lowercase
    digits = string.digits
    special = string.punctuation
    
    # Ensure the password has at least one of each type
    all_characters = upper + lower + digits + special
    password = [
        random.choice(upper),
        random.choice(lower),
        random.choice(digits),
        random.choice(special)
    ]
    
    # Fill the rest of the password length with random characters from the combined set
    password += random.choices(all_characters, k=length-4)
    
    # Shuffle the characters to ensure randomness
    random.shuffle(password)
    
    # Convert the list to a string and return
    return ''.join(password)

# Gradio interface
interface = gr.Interface(
    fn=generate_password,
    inputs=gr.Slider(8, 32, step=1, default=12, label="Password Length"),
    outputs="text",
    title="Password Generator",
    description="Generate a strong, unique password by selecting the desired length."
)

interface.launch()