RakanAlsheraiwi's picture
Update app.py
012d093 verified
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(minimum=8, maximum=32, step=1, value=12, label="Password Length"),
outputs="text",
title="Password Generator",
description="Generate a strong, unique password by selecting the desired length."
)
interface.launch()