Spaces:
Sleeping
Sleeping
Use the GPM package + draft the UI
Browse files- README.md +2 -1
- app.py +158 -5
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -13,8 +13,9 @@ short_description: 'Stateless password manager, powered by ML neural networks.'
|
|
| 13 |
|
| 14 |
## GPM: Generative Password Manager <img src="images/logo.png" alt="apehex logo" width="32" height="32">
|
| 15 |
|
| 16 |
-
Stateless password manager, powered by ML neural networks.
|
| 17 |
|
| 18 |
Licensed under the [aGPLv3][github-license].
|
| 19 |
|
|
|
|
| 20 |
[github-license]: LICENSE.md
|
|
|
|
| 13 |
|
| 14 |
## GPM: Generative Password Manager <img src="images/logo.png" alt="apehex logo" width="32" height="32">
|
| 15 |
|
| 16 |
+
[Stateless password manager][github-gpm], powered by ML neural networks.
|
| 17 |
|
| 18 |
Licensed under the [aGPLv3][github-license].
|
| 19 |
|
| 20 |
+
[github-gpm]: https://github.com/apehex/gpm
|
| 21 |
[github-license]: LICENSE.md
|
app.py
CHANGED
|
@@ -1,7 +1,160 @@
|
|
| 1 |
-
import
|
| 2 |
|
| 3 |
-
|
| 4 |
-
return "Hello " + name + "!!"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
|
| 3 |
+
import gradio
|
|
|
|
| 4 |
|
| 5 |
+
import gpm.pipeline
|
| 6 |
+
|
| 7 |
+
# META #########################################################################
|
| 8 |
+
|
| 9 |
+
STYLE = '''.white-text span { color: white; }'''
|
| 10 |
+
TITLE = '''Generative Password Manager'''
|
| 11 |
+
INTRO = '''This is a POC, do **not** use it to manage your secrets.\nStateless password manager: you don't need to save passwords, they can all be derived from a single master key.\nAlways use the same format for a given target / ID: for example the password generated for "Github" and "github.com" are different.'''
|
| 12 |
+
|
| 13 |
+
# ENUMS ########################################################################
|
| 14 |
+
|
| 15 |
+
# password level
|
| 16 |
+
CHARS = 0
|
| 17 |
+
WORDS = 1
|
| 18 |
+
|
| 19 |
+
# password alphabet
|
| 20 |
+
DIGITS = 1
|
| 21 |
+
LOWERS = 2
|
| 22 |
+
UPPERS = 4
|
| 23 |
+
SPACES = 8
|
| 24 |
+
SYMBOLS = 16
|
| 25 |
+
|
| 26 |
+
# INTRO ########################################################################
|
| 27 |
+
|
| 28 |
+
def create_intro_block(intro: str) -> dict:
|
| 29 |
+
__intro = gradio.Markdown(intro, line_breaks=True)
|
| 30 |
+
return {'intro_block': __intro}
|
| 31 |
+
|
| 32 |
+
# MASTER #######################################################################
|
| 33 |
+
|
| 34 |
+
def create_master_block() -> dict:
|
| 35 |
+
__key = gradio.Textbox(label='Key', type='text', value='', placeholder='Your master key.', lines=1, max_lines=1, scale=1, show_copy_button=True, interactive=True)
|
| 36 |
+
return {
|
| 37 |
+
'key_block': __key,}
|
| 38 |
+
|
| 39 |
+
# VOCABULARY ###################################################################
|
| 40 |
+
|
| 41 |
+
def create_vocabulary_block() -> dict:
|
| 42 |
+
__level = gradio.Radio(label='Level', type='value', value=CHARS, choices=[('Character', CHARS), ('Word', WORDS)], interactive=True)
|
| 43 |
+
__vocabulary = gradio.CheckboxGroup(label='Vocabulary', type='value', value=[DIGITS, LOWERS, UPPERS], choices=[('Digits', DIGITS), ('Lowercase', LOWERS), ('Uppercase', UPPERS), ('Spaces', SPACES), ('Symbols', SYMBOLS)], interactive=True)
|
| 44 |
+
return {
|
| 45 |
+
'level_block': __level,
|
| 46 |
+
'vocabulary_block': __vocabulary,}
|
| 47 |
+
|
| 48 |
+
# SAMPLING #####################################################################
|
| 49 |
+
|
| 50 |
+
def create_sampling_block() -> dict:
|
| 51 |
+
__length = gradio.Slider(label='Length', value=8, minimum=1, maximum=32, step=1, scale=1, interactive=True)
|
| 52 |
+
__nonce = gradio.Number(label='Nonce', value=1, minimum=0, maximum=2 ** 32, step=1, scale=1, interactive=True)
|
| 53 |
+
return {
|
| 54 |
+
'length_block': __length,
|
| 55 |
+
'nonce_block': __nonce,}
|
| 56 |
+
|
| 57 |
+
# INPUTS #######################################################################
|
| 58 |
+
|
| 59 |
+
def create_inputs_block() -> dict:
|
| 60 |
+
__target = gradio.Textbox(label='Target', type='text', value='', placeholder='The login target (URL, IP, name, etc), like "Hugging Face" or "https://github.com".', lines=1, max_lines=1, scale=1, show_copy_button=True, interactive=True)
|
| 61 |
+
__identifier = gradio.Textbox(label='Identifier', type='text', value='', placeholder='The login ID (username, email, etc), like "John Doe" or "john.doe@example.com".', lines=1, max_lines=1, scale=1, show_copy_button=True, interactive=True)
|
| 62 |
+
return {
|
| 63 |
+
'target_block': __target,
|
| 64 |
+
'identifier_block': __identifier,}
|
| 65 |
+
|
| 66 |
+
# OUTPUTS ######################################################################
|
| 67 |
+
|
| 68 |
+
def create_outputs_block() -> dict:
|
| 69 |
+
__password = gradio.Textbox(label='Password', type='text', value='', placeholder='The generated password.', lines=1, max_lines=1, scale=1, show_copy_button=True, interactive=False)
|
| 70 |
+
return {
|
| 71 |
+
'password_block': __password,}
|
| 72 |
+
|
| 73 |
+
# ACTIONS ######################################################################
|
| 74 |
+
|
| 75 |
+
def create_actions_block() -> dict:
|
| 76 |
+
__process = gradio.Button('Generate', variant='primary', size='lg', scale=1, interactive=True)
|
| 77 |
+
return {'process_block': __process,}
|
| 78 |
+
|
| 79 |
+
# STATE ########################################################################
|
| 80 |
+
|
| 81 |
+
def create_state() -> dict:
|
| 82 |
+
return {}
|
| 83 |
+
|
| 84 |
+
# LAYOUT #######################################################################
|
| 85 |
+
|
| 86 |
+
def create_layout(intro: str=INTRO) -> dict:
|
| 87 |
+
__fields = {}
|
| 88 |
+
__fields.update(create_intro_block(intro=intro))
|
| 89 |
+
with gradio.Tabs():
|
| 90 |
+
with gradio.Tab('Manager') as __main_tab:
|
| 91 |
+
__fields.update({'main_tab': __main_tab})
|
| 92 |
+
with gradio.Row(equal_height=True):
|
| 93 |
+
__fields.update(create_inputs_block())
|
| 94 |
+
with gradio.Row(equal_height=True):
|
| 95 |
+
__fields.update(create_outputs_block())
|
| 96 |
+
with gradio.Row(equal_height=True):
|
| 97 |
+
__fields.update(create_actions_block())
|
| 98 |
+
with gradio.Tab('Settings') as __settings_tab:
|
| 99 |
+
__fields.update({'settings_tab': __settings_tab})
|
| 100 |
+
with gradio.Column(scale=1):
|
| 101 |
+
with gradio.Row(equal_height=True):
|
| 102 |
+
__fields.update(create_master_block())
|
| 103 |
+
with gradio.Row(equal_height=True):
|
| 104 |
+
__fields.update(create_vocabulary_block())
|
| 105 |
+
with gradio.Row(equal_height=True):
|
| 106 |
+
__fields.update(create_sampling_block())
|
| 107 |
+
return __fields
|
| 108 |
+
|
| 109 |
+
# EVENTS #######################################################################
|
| 110 |
+
|
| 111 |
+
def generate_password(
|
| 112 |
+
master_key: str,
|
| 113 |
+
login_target: str,
|
| 114 |
+
login_id: str,
|
| 115 |
+
password_length: int,
|
| 116 |
+
password_nonce: int,
|
| 117 |
+
password_level: int,
|
| 118 |
+
password_alphabet: list,
|
| 119 |
+
) -> str:
|
| 120 |
+
return gpm.pipeline.process(
|
| 121 |
+
master_key=master_key,
|
| 122 |
+
login_target=login_target,
|
| 123 |
+
login_id=login_id,
|
| 124 |
+
password_length=password_length,
|
| 125 |
+
password_nonce=password_nonce,
|
| 126 |
+
include_lowers=(LOWERS in password_alphabet),
|
| 127 |
+
include_uppers=(UPPERS in password_alphabet),
|
| 128 |
+
include_digits=(DIGITS in password_alphabet),
|
| 129 |
+
include_symbols=(SYMBOLS in password_alphabet),
|
| 130 |
+
include_spaces=(SPACES in password_alphabet),
|
| 131 |
+
include_words=(password_level == WORDS),
|
| 132 |
+
input_vocabulary=[chr(__i) for __i in range(128)],
|
| 133 |
+
model_context_dim=8,
|
| 134 |
+
model_embedding_dim=128)
|
| 135 |
+
|
| 136 |
+
# APP ##########################################################################
|
| 137 |
+
|
| 138 |
+
def create_app(title: str=TITLE, intro: str=INTRO, style: str=STYLE) -> gradio.Blocks:
|
| 139 |
+
__fields = {}
|
| 140 |
+
with gradio.Blocks(theme=gradio.themes.Soft(), title=title, css=style) as __app:
|
| 141 |
+
# __tokenizer = psaiops.score.similarity.lib.get_tokenizer(name=model, device='cpu')
|
| 142 |
+
# create the UI
|
| 143 |
+
__fields.update(create_layout(intro=intro))
|
| 144 |
+
# init the state
|
| 145 |
+
__fields.update(create_state())
|
| 146 |
+
# wire the input fields
|
| 147 |
+
__fields['process_block'].click(
|
| 148 |
+
fn=generate_password,
|
| 149 |
+
inputs=[__fields[__k] for __k in ['key_block', 'target_block', 'identifier_block', 'length_block', 'nonce_block', 'level_block', 'vocabulary_block']],
|
| 150 |
+
outputs=__fields['password_block'],
|
| 151 |
+
queue=False,
|
| 152 |
+
show_progress='full')
|
| 153 |
+
# gradio application
|
| 154 |
+
return __app
|
| 155 |
+
|
| 156 |
+
# MAIN #########################################################################
|
| 157 |
+
|
| 158 |
+
if __name__ == '__main__':
|
| 159 |
+
__app = create_app()
|
| 160 |
+
__app.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gpmanager>=0.4
|
| 2 |
+
gradio>=5.0
|