Skip to content

Commit

Permalink
+ topos.dmg app
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnyjohnson1 committed Aug 7, 2024
1 parent 0e2a441 commit 9410f02
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,5 @@ topos/credentials.json
topos/justfile
topos/cloudbuild.yaml
dockerfile

topos.app
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ Game options are:


## Install with nix (Recommended)
1. Install nix
1. Install nix:
macos/linux: `sh <(curl -L https://nixos.org/nix/install)`
windows: `sh <(curl -L https://nixos.org/nix/install) --daemon`
windows: `sh <(curl -L https://nixos.org/nix/install) --daemon`
2. Download this repo `git clone https://github.com/jonnyjohnson1/topos-cli`
3. `cd topos-cli`
4. `nix-shell`
4. build the backend service: `nix-shell`
5.
```
topos set --spacy trf // set this value. It only needs to be set once.
topos run // start topos
```

## Install Instructions
requires `brew install just`
Expand Down
2 changes: 0 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
let
python = pkgs.python3;


in pkgs.mkShell {
buildInputs = [
pkgs.just
Expand All @@ -12,7 +11,6 @@ in pkgs.mkShell {

shellHook = ''
just build
topos set --spacy trf
topos run
'';
}
5 changes: 4 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ python:
pyi-makespec --onefile main.py
# add ('topos/config.yaml', 'topos/')
pyinstaller main.spec
create-dmg 'dist/main' --overwrite
create-dmg 'dist/main' --overwrite

dmg:
create-dmg topos.app --volicon "topos/assets/topos_blk_rounded.png" --icon "topos/assets/topos_blk_rounded.png"
Binary file added topos 1.3.dmg
Binary file not shown.
41 changes: 34 additions & 7 deletions topos/app/menu_bar_app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ..api import api
from ..downloaders.spacy_loader import download_spacy_model
from topos.utilities.utils import get_root_directory
from ..config import get_ssl_certificates

import requests
import threading
Expand All @@ -10,18 +11,37 @@
import time
import os

import warnings

ASSETS_PATH = os.path.join(get_root_directory(), "assets/topos_white.png")
API_URL = "http://0.0.0.0:13341/health"
DOCS_URL = "http://0.0.0.0:13341/docs"
ASSETS_PATH = os.path.join(get_root_directory(), "assets/topos_white.png")


def start_api():
api.start_local_api()

def start_web_app():
global API_URL, DOCS_URL
API_URL = "https://0.0.0.0:13341/health"
DOCS_URL = "https://0.0.0.0:13341/docs"
api_thread = threading.Thread(target=api.start_web_api)
api_thread.daemon = True
api_thread.start()
# Create and start the tray icon on the main thread
create_tray_icon()

def check_health(icon):
certs = get_ssl_certificates()
if not os.path.exists(certs['cert_path']):
print(f"Certificate file not found: {certs['cert_path']}")
if not os.path.exists(certs['key_path']):
print(f"Key file not found: {certs['key_path']}")

while icon.visible:
try:
response = requests.get(API_URL)
with warnings.catch_warnings(): # cert=(certs['cert_path'], certs['key_path']) #for verification, but wasn't working
warnings.filterwarnings('ignore', message='Unverified HTTPS request')
response = requests.get(API_URL, verify=False)
if response.status_code == 200:
update_status(icon, "Service is running", (170, 255, 0, 255))
else:
Expand Down Expand Up @@ -76,12 +96,19 @@ def on_exit(icon, item):
icon.visible = False
icon.stop()

def start_app():
# if __name__ == "__main__":
# Start the API in a separate thread
api_thread = threading.Thread(target=start_api)
def start_local_app():
api_thread = threading.Thread(target=api.start_local_api)
api_thread.daemon = True
api_thread.start()
# Create and start the tray icon on the main thread
create_tray_icon()

def start_web_app():
global API_URL, DOCS_URL
API_URL = "https://0.0.0.0:13341/health"
DOCS_URL = "https://0.0.0.0:13341/docs"
api_thread = threading.Thread(target=api.start_web_api)
api_thread.daemon = True
api_thread.start()
# Create and start the tray icon on the main thread
create_tray_icon()
Binary file added topos/assets/topos_blk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added topos/assets/topos_blk_rounded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions topos/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ def main():
api.start_hosted_service()
elif args.web:
from .app import menu_bar_app
api.start_web_api()
menu_bar_app.start_web_app()
else:
menu_bar_app.start_app()
from .app import menu_bar_app
menu_bar_app.start_local_app()

if args.command == 'chat':
"""
Expand Down
9 changes: 6 additions & 3 deletions topos/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ def get_openai_api_key():


def get_ssl_certificates():
project_dir = get_root_directory()
# project_dir = get_root_directory()
# print(project_dir)
# "key_path": project_dir + "/key.pem",
# "cert_path": project_dir + "/cert.pem"
return {
"key_path": project_dir + "/key.pem",
"cert_path": project_dir + "/cert.pem"
"key_path": "key.pem",
"cert_path": "cert.pem"
}


Expand Down

0 comments on commit 9410f02

Please sign in to comment.