Spaces:
Build error
Build error
Download extensions/AutoSave/script.py from LRhinehart/text-generation-webui: direct link, hf CLI and curl.
- Browser
- Download file 1.91 kB
-
https://huggingface.co/spaces/LRhinehart/text-generation-webui/resolve/main/extensions/AutoSave/script.py
- Command line
-
hf download hf://spaces/LRhinehart/text-generation-webui/extensions/AutoSave/script.py
-
curl -L -o script.py https://huggingface.co/spaces/LRhinehart/text-generation-webui/resolve/main/extensions/AutoSave/script.py
1.91 kB
| import gradio as gr | |
| import modules.shared as shared | |
| import json | |
| from datetime import datetime | |
| from pathlib import Path | |
| myprompt="no data" | |
| params = { | |
| "name": "AutoSave", | |
| "display_name": "AutoSave", | |
| "activate": True, | |
| "custom string": "n/a", | |
| } | |
| def save_data(string,timestamp=True): | |
| mydate=datetime.now().strftime('%Y%m%d') | |
| fname = f"{mydate}_text_log.txt" | |
| file_path=f'extensions/{params["name"]}/output' | |
| if not Path(file_path).exists(): | |
| Path(file_path).mkdir() | |
| model = shared.model_name | |
| adapter = getattr(shared.model,'active_adapter','None') | |
| with open(Path(f'{file_path}/{fname}'), 'a+', encoding='utf-8') as f: | |
| f.write(json.dumps({"model": model, "adapter": adapter, "prompt" : myprompt, "reply":string} , indent=2 )) | |
| return Path(f'{file_path}/{fname}') | |
| def input_modifier(string): | |
| """ | |
| This function is applied to your text inputs before | |
| they are fed into the model. | |
| """ | |
| global myprompt | |
| myprompt=string | |
| #print (f"input query:{myprompt}") | |
| return string | |
| def output_modifier(string): | |
| """ | |
| This function is applied to the model outputs. | |
| """ | |
| if not params['activate']: | |
| return string | |
| save_data(string,timestamp=False) | |
| return string | |
| def bot_prefix_modifier(string): | |
| """ | |
| This function is only applied in chat mode. It modifies | |
| the prefix text for the Bot and can be used to bias its | |
| behavior. | |
| """ | |
| return string | |
| def ui(): | |
| # Gradio elements | |
| activate = gr.Checkbox(value=params['activate'], label='Activate AutoSave') | |
| #string = gr.Textbox(value=params["bias string"], label='Custom Text') | |
| # Event functions to update the parameters in the backend | |
| #string.change(lambda x: params.update({"custom string": x}), string, None) | |
| activate.change(lambda x: params.update({"activate": x}), activate, None) | |