From 0e3b2aa7e2230d196a2d66084ab42faaa921fbaa Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:27:22 -0600 Subject: [PATCH] Fixed webui issues, hopefully --- subgen.py | 59 +++++++++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/subgen.py b/subgen.py index e5c493d..c839a00 100644 --- a/subgen.py +++ b/subgen.py @@ -96,8 +96,6 @@ def update_env_variables(): if transcribe_device == "gpu": transcribe_device = "cuda" - set_env_variables('subgen.env') - update_env_variables() if monitor: @@ -212,34 +210,22 @@ def form_get(): html_content += "
" return html_content @@ -264,34 +250,29 @@ async def form_post(request: Request): existing_vars[var.strip()] = val.strip() # Update the file with new values from the form - with open(f"{env_path}", "w") as file: + with open(env_path, "w") as file: for key, value in form_data.items(): # Normalize the key to uppercase key = key.upper() # Convert the value to the correct type (boolean or string) - if isinstance(env_variables[key]['default'], bool): - value = value.strip().lower() == 'true' - else: - value = value.strip() - # Write to file only if the value is different from the default - if env_variables[key]["default"] != value and value: - # Check if the variable already exists and if the value is different - if key in existing_vars and existing_vars[key] != str(value): - # Update the existing variable with the new value - existing_vars[key] = str(value) - elif key not in existing_vars: - # Add the new variable to the dictionary - existing_vars[key] = str(value) - elif key in existing_vars: - # Remove the entry from the existing variables if the value is empty - del existing_vars[key] + value = value.strip() if not isinstance(env_variables[key]["default"], bool) else convert_to_bool(value.strip()) + # Retrieve the current environment variable value + env_value = os.getenv(key) + if key in os.environ: del os.environ[key] + # Write to file only if the value is different from the os.getenv and has a value + if env_value != value and (value is not None and value != '') and (env_variables[key]["default"] != value): + # Update the existing variable with the new value + existing_vars[key] = str(value) + # Update the environment variable + os.environ[key] = str(value) # Write the updated variables to the file for var, val in existing_vars.items(): file.write(f"{var}={val}\n") + update_env_variables() - return(f"Configuration saved to {env_path}, reloading your subgen with your new values!") + return f"Configuration saved to {env_path}, reloading your subgen with your new values!" @app.get("/status") def status():