fix: Move widget commands outside cached function to avoid unexpected behavior
This commit is contained in:
14
alwrity.py
14
alwrity.py
@@ -218,7 +218,19 @@ def main():
|
|||||||
setup_environment_paths()
|
setup_environment_paths()
|
||||||
sidebar_configuration()
|
sidebar_configuration()
|
||||||
|
|
||||||
if check_api_keys():
|
missing_keys = check_api_keys()
|
||||||
|
if missing_keys:
|
||||||
|
st.warning(f"API keys not found: {', '.join(missing_keys)}. Please provide them below. Restart the app after saving the keys.")
|
||||||
|
with st.form(key='api_keys_form'):
|
||||||
|
for key in missing_keys:
|
||||||
|
st.text_input(f"{key}:", type="password", key=key)
|
||||||
|
if st.form_submit_button("Save Keys"):
|
||||||
|
with open(".env", "a") as env_file:
|
||||||
|
for key in missing_keys:
|
||||||
|
key_value = st.session_state[key]
|
||||||
|
env_file.write(f"{key}={key_value}\n")
|
||||||
|
st.success("API keys saved successfully! Please restart the application.")
|
||||||
|
else:
|
||||||
setup_tabs()
|
setup_tabs()
|
||||||
modify_prompts_sidebar()
|
modify_prompts_sidebar()
|
||||||
|
|
||||||
|
|||||||
@@ -5,28 +5,17 @@ from dotenv import load_dotenv
|
|||||||
import os
|
import os
|
||||||
import streamlit as st
|
import streamlit as st
|
||||||
|
|
||||||
@st.cache_data
|
import os
|
||||||
|
import streamlit as st
|
||||||
|
|
||||||
def check_api_keys():
|
def check_api_keys():
|
||||||
"""Checks for API keys and prompts for input if not found."""
|
"""Checks for API keys and returns a list of missing keys."""
|
||||||
required_keys = ["GOOGLE_API_KEY", "OPENAI_API_KEY", "ANTHROPIC_API_KEY"]
|
required_keys = ["GOOGLE_API_KEY", "OPENAI_API_KEY", "ANTHROPIC_API_KEY"]
|
||||||
missing_keys = []
|
missing_keys = []
|
||||||
for key in required_keys:
|
for key in required_keys:
|
||||||
if not os.getenv(key):
|
if not os.getenv(key):
|
||||||
missing_keys.append(key)
|
missing_keys.append(key)
|
||||||
|
return missing_keys
|
||||||
if missing_keys:
|
|
||||||
st.warning(f"API keys not found: {', '.join(missing_keys)}. Please provide them below. Restart the app after saving the keys.")
|
|
||||||
with st.form(key='api_keys_form'):
|
|
||||||
for key in missing_keys:
|
|
||||||
st.text_input(f"{key}:", type="password", key=key)
|
|
||||||
if st.form_submit_button("Save Keys"):
|
|
||||||
with open(".env", "a") as env_file:
|
|
||||||
for key in missing_keys:
|
|
||||||
key_value = st.session_state[key]
|
|
||||||
env_file.write(f"{key}={key_value}\n")
|
|
||||||
st.success("API keys saved successfully! Please restart the application.")
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user