File size: 1,040 Bytes
6fac62a
 
 
 
 
 
 
 
 
 
 
 
aca1410
6fac62a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()