|
import gradio as gr |
|
import random |
|
import string |
|
|
|
|
|
def generate_random_password(length): |
|
|
|
characters = string.ascii_letters + string.digits + "*&%@!" |
|
|
|
|
|
password = "".join(random.choice(characters) for _ in range(length)) |
|
|
|
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() |
|
|