import gradio as gr import random as r import string # Define character sets lower_charset = string.ascii_lowercase upper_charset = string.ascii_uppercase digitset = string.digits symbolset = '!@#$%^&*()-_=+~:;{}[]/|<>?' # Define character set options options = { '1': ('Uppercase Letters Only', upper_charset), '2': ('Lowercase Letters Only', lower_charset), '3': ('Numbers Only', digitset), '4': ('Symbols Only', symbolset), '5': ('Uppercase and Lowercase Letters', upper_charset + lower_charset), '6': ('Uppercase Letters and Numbers', upper_charset + digitset), '7': ('Uppercase Letters and Symbols', upper_charset + symbolset), '8': ('Lowercase Letters and Numbers', lower_charset + digitset), '9': ('Lowercase Letters and Symbols', lower_charset + symbolset), '10': ('Numbers and Symbols', digitset + symbolset), '11': ('Symbols, Lowercase Letters, and Uppercase Letters', symbolset + lower_charset + upper_charset), '12': ('Symbols, Lowercase Letters, and Numbers', symbolset + lower_charset + digitset), '13': ('Symbols, Uppercase Letters, and Numbers', symbolset + upper_charset + digitset), '14': ('All Characters', upper_charset + lower_charset + digitset + symbolset) } def generate_password(char_type, length): if char_type not in options: return "Invalid choice. Please select a valid option." possible_chars = options[char_type][1] generated_passwd = ''.join(r.choices(possible_chars, k=length)) return generated_passwd # Create Gradio interface iface = gr.Interface( fn=generate_password, inputs=[ gr.Dropdown(list(options, label="Choose the character set you want to use for your password", value=options[14]), gr.Slider(1, 50, step=1, label="Enter the desired length of your password", value=12) ], outputs="text", title="Password Generator", description="Generate a strong password based on your chosen character set and length." ) # Launch the interface iface.launch()