├── README.md ├── script.py └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | # AutoSave 2 | ![image](https://github.com/ill13/AutoSave/assets/10509740/3577e6bc-1ca4-4699-977c-bd8b75ec7176) 3 | 4 | 5 | An auto save extension for text generated with the oobabooga WebUI. 6 | 7 | If you've ever lost a great response or forgot to copy and save your perfect prompt, **AutoSave** is for you! 8 | 9 | - 100% offline 10 | - Saves every prompt and every response to the host 11 | - Creates a new log file for every day 12 | - Appends the prompt and response to the log file as JSON 13 | - Logs are located in *PATH_TO_text-generation-webui/extensions/AutoSave/output/* 14 | 15 | ### How to use: 16 | 17 | Fire up a command prompt | shell: 18 | 19 | ```cd PATH_TO_text-generation-webui/extensions``` 20 | 21 | Now clone this repo: 22 | 23 | ```git clone https://github.com/ill13/AutoSave``` 24 | 25 | Finally enable the extension in the *Session* tab 26 | 27 | ![image](https://github.com/ill13/AutoSave/assets/10509740/92a131fc-7f65-4c62-94e8-85393b859714) 28 | 29 | ### Future: 30 | 31 | I may add the generation properties [*model, seed, settings*] at a later point. 32 | -------------------------------------------------------------------------------- /script.py: -------------------------------------------------------------------------------- 1 | import gradio as gr 2 | import modules.shared as shared 3 | import json 4 | from datetime import datetime 5 | from pathlib import Path 6 | 7 | 8 | myprompt="no data" 9 | 10 | params = { 11 | "name": "AutoSave", 12 | "display_name": "AutoSave", 13 | "activate": True, 14 | "custom string": "n/a", 15 | } 16 | 17 | def save_data(string,timestamp=True): 18 | mydate=datetime.now().strftime('%Y%m%d') 19 | fname = f"{mydate}_text_log.txt" 20 | 21 | file_path=f'extensions/{params["name"]}/output' 22 | 23 | if not Path(file_path).exists(): 24 | Path(file_path).mkdir() 25 | 26 | model = shared.model_name 27 | adapter = getattr(shared.model,'active_adapter','None') 28 | 29 | with open(Path(f'{file_path}/{fname}'), 'a+', encoding='utf-8') as f: 30 | f.write(json.dumps({"model": model, "adapter": adapter, "prompt" : myprompt, "reply":string} , indent=2 )) 31 | 32 | return Path(f'{file_path}/{fname}') 33 | 34 | def input_modifier(string): 35 | """ 36 | This function is applied to your text inputs before 37 | they are fed into the model. 38 | """ 39 | global myprompt 40 | myprompt=string 41 | #print (f"input query:{myprompt}") 42 | 43 | return string 44 | 45 | def output_modifier(string): 46 | """ 47 | This function is applied to the model outputs. 48 | """ 49 | if not params['activate']: 50 | return string 51 | 52 | save_data(string,timestamp=False) 53 | 54 | return string 55 | 56 | def bot_prefix_modifier(string): 57 | """ 58 | This function is only applied in chat mode. It modifies 59 | the prefix text for the Bot and can be used to bias its 60 | behavior. 61 | """ 62 | return string 63 | 64 | def ui(): 65 | # Gradio elements 66 | activate = gr.Checkbox(value=params['activate'], label='Activate AutoSave') 67 | #string = gr.Textbox(value=params["bias string"], label='Custom Text') 68 | 69 | # Event functions to update the parameters in the backend 70 | #string.change(lambda x: params.update({"custom string": x}), string, None) 71 | activate.change(lambda x: params.update({"activate": x}), activate, None) 72 | 73 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ill13 2 | output/ 3 | old/ 4 | 5 | # Byte-compiled / optimized / DLL files 6 | __pycache__/ 7 | *.py[cod] 8 | *$py.class 9 | 10 | # C extensions 11 | *.so 12 | 13 | # Distribution / packaging 14 | .Python 15 | build/ 16 | develop-eggs/ 17 | dist/ 18 | downloads/ 19 | eggs/ 20 | .eggs/ 21 | lib/ 22 | lib64/ 23 | parts/ 24 | sdist/ 25 | var/ 26 | wheels/ 27 | share/python-wheels/ 28 | *.egg-info/ 29 | .installed.cfg 30 | *.egg 31 | MANIFEST 32 | 33 | # PyInstaller 34 | # Usually these files are written by a python script from a template 35 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 36 | *.manifest 37 | *.spec 38 | 39 | # Installer logs 40 | pip-log.txt 41 | pip-delete-this-directory.txt 42 | 43 | # Unit test / coverage reports 44 | htmlcov/ 45 | .tox/ 46 | .nox/ 47 | .coverage 48 | .coverage.* 49 | .cache 50 | nosetests.xml 51 | coverage.xml 52 | *.cover 53 | *.py,cover 54 | .hypothesis/ 55 | .pytest_cache/ 56 | cover/ 57 | 58 | # Translations 59 | *.mo 60 | *.pot 61 | 62 | # Django stuff: 63 | *.log 64 | local_settings.py 65 | db.sqlite3 66 | db.sqlite3-journal 67 | 68 | # Flask stuff: 69 | instance/ 70 | .webassets-cache 71 | 72 | # Scrapy stuff: 73 | .scrapy 74 | 75 | # Sphinx documentation 76 | docs/_build/ 77 | 78 | # PyBuilder 79 | .pybuilder/ 80 | target/ 81 | 82 | # Jupyter Notebook 83 | .ipynb_checkpoints 84 | 85 | # IPython 86 | profile_default/ 87 | ipython_config.py 88 | 89 | # pyenv 90 | # For a library or package, you might want to ignore these files since the code is 91 | # intended to run in multiple environments; otherwise, check them in: 92 | # .python-version 93 | 94 | # pipenv 95 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 96 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 97 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 98 | # install all needed dependencies. 99 | #Pipfile.lock 100 | 101 | # poetry 102 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 103 | # This is especially recommended for binary packages to ensure reproducibility, and is more 104 | # commonly ignored for libraries. 105 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 106 | #poetry.lock 107 | 108 | # pdm 109 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 110 | #pdm.lock 111 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 112 | # in version control. 113 | # https://pdm.fming.dev/#use-with-ide 114 | .pdm.toml 115 | 116 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 117 | __pypackages__/ 118 | 119 | # Celery stuff 120 | celerybeat-schedule 121 | celerybeat.pid 122 | 123 | # SageMath parsed files 124 | *.sage.py 125 | 126 | # Environments 127 | .env 128 | .venv 129 | env/ 130 | venv/ 131 | ENV/ 132 | env.bak/ 133 | venv.bak/ 134 | 135 | # Spyder project settings 136 | .spyderproject 137 | .spyproject 138 | 139 | # Rope project settings 140 | .ropeproject 141 | 142 | # mkdocs documentation 143 | /site 144 | 145 | # mypy 146 | .mypy_cache/ 147 | .dmypy.json 148 | dmypy.json 149 | 150 | # Pyre type checker 151 | .pyre/ 152 | 153 | # pytype static type analyzer 154 | .pytype/ 155 | 156 | # Cython debug symbols 157 | cython_debug/ 158 | 159 | # PyCharm 160 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 161 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 162 | # and can be added to the global gitignore or merged into this file. For a more nuclear 163 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 164 | #.idea/ 165 | --------------------------------------------------------------------------------