tools / app.py
wangjun's picture
Update app.py
aca1410
import gradio as gr
import random
import string
def generate_random_password(length):
# 定义密码中可以包含的字符集合
characters = string.ascii_letters + string.digits + "*&%@!"
# 利用 random.choice 随机选择 length 个字符生成密码
password = "".join(random.choice(characters) for _ in range(length))
print(password)
return password
def generate_random_passwords(length, count):
return "\n".join([generate_random_password(length=length) for _ in range(count)])
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
length = gr.Slider(label="Length", minimum=8, value=15, maximum=25, step=1)
number = gr.Slider(label="Number", minimum=1, value=3, maximum=10, step=1)
greet_btn = gr.Button("生成")
output = gr.TextArea(label="结果")
greet_btn.click(
fn=generate_random_passwords,
inputs=[length, number],
outputs=output,
api_name="generate_random_password",
)
demo.launch()