Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bin/create_app_bundle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ echo "Copying build/dist artifacts to SecureAI.app/Contents/MacOS/"
cp -a build/dist/secure-ai SecureAI.app/Contents/MacOS/SecureAI
cp -a build/dist/site-packages SecureAI.app/Contents/MacOS/
cp resources/SecureAI.icns SecureAI.app/Contents/Resources
cp resources/menubar.ico SecureAI.app/Contents/Resources

echo "Generating SecureAI.app/Contents/Info.plist"
cat << EOF > SecureAI.app/Contents/Info.plist
Expand All @@ -33,8 +34,10 @@ cat << EOF > SecureAI.app/Contents/Info.plist
<string>1.0</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>LSUIElement</key>
<true/>
</dict>
</plist>
EOF

echo "Done!"
echo "Done!"
2,356 changes: 1,195 additions & 1,161 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ streamlit-feedback = "^0.0.9"
tabulate = "^0.9.0"
torch = ">=2.0.0, !=2.0.1, !=2.1.0"
watchdog = "^3.0.0"
rumps = "^0.4.0"

[tool.poetry.group.dev.dependencies]
black = "^23.3.0"
Expand Down
Binary file added resources/menubar.ico
Binary file not shown.
1 change: 1 addition & 0 deletions secure_ai/Docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def configure_retriever(linked_files, db_path, model_dir_embeddings, embeddings_
st.stop()

db_index_file = os.path.join(db_path, "db_index.txt")
old_files = []
try:
with open(db_index_file, 'r') as index_file:
old_files = [line.strip() for line in index_file.readlines()]
Expand Down
22 changes: 10 additions & 12 deletions secure_ai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,12 @@ def check_trial_period(trial_license):
print(f"Current timestamp: {time.asctime(time.localtime(current_timestamp))}")
# check whether the saved trial time plus trial period is greater than the current time. If so this
# indicates the trial period is over
return True if current_timestamp < trial_timestamp else False
return current_timestamp < trial_timestamp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha both of these are great changes and obvious from looking from the outside.



def config_exists(data_dir):
config_path = os.path.join(data_dir, CONFIG_FILE_NAME)
if os.path.exists(config_path):
return True
else:
return False
return os.path.exists(config_path)


def configure_data_dir():
Expand All @@ -167,13 +164,14 @@ def configure_data_dir():
:return:
"""
home_directory = str(Path.home())
secure_ai_data_dir = os.path.join(home_directory, ".secure_ai")

if os.path.exists(secure_ai_data_dir):
with open(secure_ai_data_dir, 'r') as file:
data_dir = file.read()
if config_exists(data_dir):
return data_dir
for home_path in (".secure_ai", "SecureAI"):
secure_ai_data_dir = os.path.join(home_directory, home_path)

if os.path.exists(secure_ai_data_dir):
with open(secure_ai_data_dir, 'r') as file:
data_dir = file.read()
if config_exists(data_dir):
return data_dir

data_dir = st.text_input(f"Please enter the Secure AI root directory (containing {CONFIG_FILE_NAME} and the data folders):")
if not data_dir:
Expand Down
95 changes: 76 additions & 19 deletions secure_ai/__main__.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,91 @@
import asyncio
import atexit
import os
import os.path
import pathlib
import platform
from streamlit import config as _config
import streamlit.web.bootstrap as bootstrap
import signal
import sys
import threading
import webbrowser

HERE = pathlib.Path(__file__).parent
from streamlit import config
from streamlit.web import bootstrap


def app():
system_name = platform.system()

if system_name == "Darwin":
headless = False
else:
headless = True

# Turn off file change monitoring and run in headless mode
_config.set_option("server.port", 8501)
_config.set_option("server.address", "0.0.0.0")
_config.set_option("server.headless", headless)
_config.set_option("server.fileWatcherType", None)
_config.set_option("browser.gatherUsageStats", False)
_config.set_option("client.toolbarMode", "minimal")
config.set_option("server.port", 8501)
config.set_option("server.address", "0.0.0.0")
config.set_option("server.headless", True)
config.set_option("server.fileWatcherType", None)
config.set_option("browser.gatherUsageStats", False)
config.set_option("client.toolbarMode", "minimal")

root = pathlib.Path(__file__).parent

bootstrap.run(
str(HERE.joinpath("Docs.py")),
str(root.joinpath("Docs.py")),
command_line=None,
args=list(),
flag_options=dict(),
)

def mac_app():
# run app() in a background thread
bootstrap._set_up_signal_handler = lambda x: None
def loop_in_thread():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(app())
t = threading.Thread(target=loop_in_thread, daemon=True)
t.start()

version = 'SecureAI'
icon = None

# look for the contents directory of the app bundle
contents_path = os.path.dirname(os.path.dirname(sys.executable))

# parse the version from the Info.plist
info_plist_path = os.path.join(contents_path, 'Info.plist')
if os.path.exists(info_plist_path):
with open(info_plist_path, 'rb') as f:
import plistlib
try:
load_plist = plistlib.load
except AttributeError:
load_plist = plistlib.readPlist
plist = load_plist(f)
version = plist['CFBundleGetInfoString']

# find the menubar icon
icon_paths = [os.path.join(contents_path, 'Resources/menubar.ico'),
'resources/menubar.ico']
for icon_path in icon_paths:
if os.path.exists(icon_path):
icon = icon_path

# configure and run the menubar app
import rumps
mac = rumps.App("SecureAI", icon=icon)
mac.menu = [
rumps.MenuItem(version),
None,
rumps.MenuItem("Open", callback=lambda x: webbrowser.open("http://localhost:8501")),
None,
]
mac.run()

def check_port_in_use():
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
if not s.connect_ex(('localhost', 8501)):
print("ERROR: Port 8501 is already in use!")
sys.exit(1)

if __name__ == "__main__":
app()
check_port_in_use()
if sys.platform == 'darwin':
mac_app()
else:
app()
1 change: 0 additions & 1 deletion secure_ai/pages/Code.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from jinja2 import Template
from llama_cpp import Llama
from secure_ai import CONFIG_FILE_NAME, check_trial_period, configure_data_dir, read_config

Expand Down