kailashlale commited on
Commit
bb9d92e
·
1 Parent(s): edd76db

Added Day04 project

Browse files
Files changed (3) hide show
  1. README.md +0 -1
  2. app.py +73 -0
  3. requirements.txt +1 -0
README.md CHANGED
@@ -10,5 +10,4 @@ pinned: false
10
  license: mit
11
  short_description: Password generator built with Python and Gradio
12
  ---
13
-
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
10
  license: mit
11
  short_description: Password generator built with Python and Gradio
12
  ---
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ import string
3
+ import gradio as gr
4
+
5
+ def generator(pass_length,option,percent_syb,percent_num):
6
+ length = int(pass_length)
7
+ percent_symbol = int(percent_syb)
8
+ percent_number = int(percent_num)
9
+
10
+ number_count = max(1,int(length * percent_number/100))
11
+ symbol_count = max(1,int(length * percent_symbol/100))
12
+
13
+ if option == "Letters + Numbers + Symbols":
14
+ letter_count = max(0,length - number_count - symbol_count)
15
+
16
+ if option == "Letters + Numbers":
17
+ symbol_count = 0
18
+ letter_count = max(0,length - number_count)
19
+
20
+ if option == "Letters + Symbols":
21
+ number_count = 0
22
+ letter_count = max(0,length - symbol_count)
23
+
24
+ if option == "Letters only":
25
+ number_count = 0
26
+ symbol_count = 0
27
+ letter_count = max(0,length)
28
+
29
+ num_list = random.choices(string.digits, k=number_count)
30
+ syb_list = random.choices(string.punctuation, k=symbol_count)
31
+ str_list = random.choices(string.ascii_letters, k=letter_count)
32
+ pass_list = str_list + num_list + syb_list
33
+
34
+ random.shuffle(pass_list)
35
+ password = "".join(pass_list)
36
+
37
+ count_result = f"Letters: {letter_count}, Symbols: {symbol_count}, Numbers: {number_count}"
38
+ password_result = password
39
+
40
+ return count_result, password_result
41
+
42
+
43
+ with gr.Blocks (title="Day 3: Password Generator") as demo:
44
+ gr.Markdown("# Password Generator")
45
+ with gr.Column():
46
+ with gr.Row():
47
+ password_length=gr.Slider(minimum=8,maximum=32, step=1, label="Length of your password")
48
+ opt_selector=gr.Dropdown(
49
+ choices=("Letters + Numbers",
50
+ "Letters + Symbols",
51
+ "Letters + Numbers + Symbols",
52
+ "Letters only"),
53
+ label= "Password should include",
54
+ value="Letters only"
55
+ )
56
+ with gr.Row():
57
+ per_sym=gr.Slider(minimum=5,maximum=40, step=5,
58
+ label="Percentage of symbols in password")
59
+ per_num=gr.Slider(minimum=5,maximum=40, step=5,
60
+ label="Percentage of numbers in password")
61
+ with gr.Row():
62
+ count_area= gr.Textbox(label="Character Count", lines=1)
63
+ password_area= gr.Textbox(label="Your Password", lines=1)
64
+ generate_btn= gr.Button("Generate", variant="primary")
65
+
66
+
67
+ generate_btn.click( # pylint: disable=no-member
68
+ fn=generator,
69
+ inputs=(password_length, opt_selector, per_sym, per_num),
70
+ outputs=(count_area,password_area)
71
+ )
72
+
73
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio