-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
732 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*Toolkit.exe filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[server] | ||
enableXsrfProtection = false | ||
maxUploadSize = 1000 | ||
maxUploadSize = 1000 | ||
|
||
[client] | ||
toolbarMode = "viewer" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
# Copyright (c) 2024 Microsoft Corporation. All rights reserved. | ||
from javascript.styles import add_styles | ||
import components.app_user as au | ||
import streamlit as st | ||
import components.app_terminator as at | ||
import components.app_openai as ao | ||
|
||
def load_multipage_app(): | ||
#Load user if logged in | ||
user = au.app_user() | ||
user.view_get_info() | ||
|
||
#Terminate app (if needed for .exe) | ||
terminator = at.app_terminator() | ||
terminator.terminate_app_btn() | ||
|
||
#OpenAI key set | ||
app_openai = ao.app_openai() | ||
app_openai.api_info() | ||
|
||
#load css | ||
# add_styles() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) 2024 Microsoft Corporation. All rights reserved. | ||
import streamlit as st | ||
from util.openai_instance import get_key_env | ||
from util.SecretsHandler import SecretsHandler | ||
|
||
class app_openai: | ||
def _is_api_key_configured(self): | ||
secrets = SecretsHandler() | ||
if secrets.get_secret("api_key") != '': | ||
return True | ||
elif get_key_env() != '': | ||
return True | ||
return False | ||
|
||
def api_info(self): | ||
if not self._is_api_key_configured(): | ||
st.error("No OpenAI key found in the environment. Please add it in the settings.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright (c) 2024 Microsoft Corporation. All rights reserved. | ||
import streamlit as st | ||
from util.session_variables import SessionVariables | ||
import psutil | ||
import keyboard | ||
import time | ||
import os | ||
|
||
class app_terminator: | ||
|
||
sv = None | ||
|
||
def __init__(self, sv = None): | ||
if "off_btn_disabled" not in st.session_state: | ||
st.session_state.off_btn_disabled = False | ||
if sv is not None: | ||
self.sv = sv | ||
else: | ||
self.sv = SessionVariables('home') | ||
|
||
def _on_click(self): | ||
def click(): | ||
st.session_state.off_btn_disabled = not st.session_state.off_btn_disabled | ||
return click | ||
|
||
def terminate_app_btn(self): | ||
if self.sv.mode.value != 'cloud': | ||
exit_app = st.sidebar.button("🔴 Terminate application", disabled=st.session_state.off_btn_disabled, on_click=self._on_click) | ||
if exit_app: | ||
st.text("Shutting down application...") | ||
time.sleep(2) | ||
pid = os.getpid() | ||
keyboard.press_and_release('ctrl+w') | ||
p = psutil.Process(pid) | ||
p.terminate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
from util.openai_instance import get_key_env | ||
from util.SecretsHandler import SecretsHandler | ||
import streamlit as st | ||
import time | ||
from util.session_variables import SessionVariables | ||
|
||
key = 'openaikey' | ||
def on_change(handler, key = None, value = None): | ||
def change(): | ||
handler.write_secret('api_key', st.session_state[key] if key else value) | ||
return change | ||
|
||
def main(): | ||
st.header("Settings") | ||
sv = SessionVariables('home') | ||
|
||
if key not in st.session_state: | ||
st.session_state[key] = '' | ||
|
||
secrets_handler = SecretsHandler() | ||
placeholder = "Enter key here..." | ||
secret = secrets_handler.get_secret("api_key") | ||
|
||
is_mode_cloud = sv.mode.value == 'cloud' | ||
|
||
secret_input = st.text_input('Enter your OpenAI key', key=key, type="password", disabled=is_mode_cloud, placeholder=placeholder, value=secret, on_change=on_change(secrets_handler, key)) | ||
|
||
if secret and len(secret): | ||
st.info("Your key is saved securely.") | ||
clear_btn = st.button("Clear local key") | ||
|
||
if clear_btn: | ||
on_change(secrets_handler, value='')() | ||
time.sleep(0.3) | ||
st.rerun() | ||
|
||
if secret_input and secret_input != secret: | ||
st.rerun() | ||
elif get_key_env() == '': | ||
st.warning("No OpenAI key found in the environment. Please insert one above.") | ||
elif not secret_input and not secret: | ||
st.info("Using key from the environment.") | ||
|
||
if __name__ == "__main__": | ||
main() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
import streamlit as st | ||
|
||
class SecretsHandler: | ||
_instance = None | ||
_directory = ".streamlit" | ||
|
||
def __init__(self): | ||
if not os.path.exists(self._directory): | ||
os.makedirs(self._directory) | ||
with(open(os.path.join(self._directory, "secrets.toml"), "w")) as f: | ||
f.write("") | ||
|
||
def __new__(cls): | ||
if cls._instance is None: | ||
cls._instance = super().__new__(cls) | ||
|
||
return cls._instance | ||
|
||
def write_secret(self, key, value): | ||
with(open(os.path.join(self._directory, "secrets.toml"), "w")) as f: | ||
f.write(f"{key} = '{value}'") | ||
|
||
def get_secret(self, key) -> str: | ||
if st.secrets and key in st.secrets: | ||
return st.secrets[key] | ||
return '' | ||
|
Empty file.
Oops, something went wrong.