Skip to content

Commit 18abfb4

Browse files
committed
Minor changes
1 parent 965fb98 commit 18abfb4

File tree

4 files changed

+143
-4
lines changed

4 files changed

+143
-4
lines changed

examples/subconscious.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self):
4646
# DB connection and conversation config
4747
self.conn = sqlite3.connect("./data/memory.db", check_same_thread=False)
4848
self.memory = SqliteSaver(self.conn)
49-
self.config = {"configurable": {"thread_id": "general"}}
49+
self.config = {"configurable": {"thread_id": "main"}}
5050

5151
def invoke(self, messages):
5252
return self.model.invoke(messages)

installer/src/main.py

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
""" This module is the installer for the Subconscious release distributable. """
2+
import os
3+
import sys
4+
import shutil
5+
import ctypes
6+
import zipfile
7+
import requests
8+
import tempfile
9+
import flet as ft
10+
11+
from titlebar import TitleBar
12+
13+
14+
def is_admin():
15+
try:
16+
return ctypes.windll.shell32.IsUserAnAdmin()
17+
except:
18+
return False
19+
20+
def download_latest_release(download_dir, pb):
21+
""" Download the latest release of the Subconscious app """
22+
# GitHub API URL for the latest release
23+
url = "https://api.github.com/repos/baebranch/subconscious/releases/latest"
24+
25+
# Send a GET request to the GitHub API
26+
response = requests.get(url)
27+
response.raise_for_status() # Raise an exception for HTTP errors
28+
file_size = int(response.headers.get('Content-Length', 0))
29+
30+
# Parse the JSON response
31+
release_data = response.json()
32+
33+
# Get the URL of the asset to download (assuming the first asset)
34+
asset = release_data['assets'][0]
35+
download_url = asset['browser_download_url']
36+
asset_name = asset['name']
37+
38+
# Download the asset
39+
download_response = requests.get(download_url, stream=True)
40+
download_response.raise_for_status()
41+
42+
# Save the asset to the specified directory
43+
file_path = os.path.join(download_dir, asset_name)
44+
with open(file_path, 'wb') as file:
45+
for chunk in download_response.iter_content(chunk_size=8192):
46+
file.write(chunk)
47+
48+
return file_path
49+
50+
51+
def extract_to_program_files(zip_path, program_files_dir):
52+
""" Extract the downloaded zip file to the Program Files directory """
53+
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
54+
zip_ref.extractall(program_files_dir)
55+
56+
57+
def main(page: ft.Page):
58+
""" Main function to initiate the installer UI """
59+
# Window size
60+
page.visible = False
61+
page.window.width = page.window.min_width = page.window.max_width = 450
62+
page.window.height = page.window.min_height = page.window.max_height = 250
63+
page.window.center()
64+
page.padding = 0
65+
page.spacing = 0
66+
page.window.frameless = False
67+
page.window.title_bar_hidden = True
68+
page.theme_mode = ft.ThemeMode.SYSTEM
69+
70+
# UI Config
71+
done = ft.TextButton("Done", on_click=lambda _: page.window.close(), style=ft.ButtonStyle(shape=ft.RoundedRectangleBorder(radius=5)), visible=False)
72+
step = ft.Text("Installing...", size=15)
73+
pb = ft.ProgressBar(width=430, bar_height=5, height=5)
74+
75+
# Layout
76+
page.add(TitleBar(page, title="Subconscious Installer"))
77+
page.add(ft.Container(content=
78+
ft.Column(
79+
[
80+
ft.Row([
81+
ft.Text("Subconscious", size=25, color=ft.Colors.PRIMARY),
82+
], alignment="left", spacing=0),
83+
step,
84+
pb,
85+
ft.Row([
86+
done
87+
], expand=True)
88+
],
89+
spacing=20, expand=True, alignment=ft.alignment.top_center
90+
),
91+
padding=ft.padding.only(20, 20, 20, 20))
92+
)
93+
page.visible = True
94+
page.update()
95+
96+
try:
97+
# Create a temporary directory
98+
with tempfile.TemporaryDirectory() as temp_dir:
99+
# Download the latest release to the temporary directory
100+
step.value = "Downloading..."
101+
pb.value = 0.0
102+
page.update()
103+
zip_path = download_latest_release(temp_dir, pb)
104+
105+
# Define the Program Files directory
106+
program_files_dir = os.path.join(os.environ['ProgramFiles'], 'Subconscious')
107+
step.value = f"Installing to {program_files_dir}..."
108+
pb.value = 0.50
109+
page.update()
110+
111+
# Ensure the Program Files directory exists
112+
os.makedirs(program_files_dir, exist_ok=True)
113+
114+
# Extract the downloaded zip file to the Program Files directory
115+
step.value = "Extracting files..."
116+
pb.value = 0.75
117+
page.update()
118+
extract_to_program_files(zip_path, program_files_dir)
119+
done.visible = True
120+
step.value = "Installation completed successfully!"
121+
pb.value = 1.0
122+
page.update()
123+
except Exception as e:
124+
pb.value = 0
125+
done.visible = True
126+
step.value = "An error occurred, could not install"
127+
page.update()
128+
print(e)
129+
130+
131+
if __name__ == "__main__":
132+
if is_admin():
133+
print("Already running as administrator.")
134+
ft.app(target=main)
135+
else:
136+
print("Attempting to run as administrator...")
137+
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)

src/components/main_window.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class MessageList(ft.ListView):
1616
def __init__(self, *args, **kwargs):
1717
super().__init__(*args, **kwargs)
1818
self.expand = 1
19+
self.width = 750
1920
self.spacing = 10
2021
self.loaded = False
2122
self.active = False
@@ -232,7 +233,7 @@ def render_settings(title, key, val):
232233
# Configuration required for LLM default message
233234
self.configure = ft.Container(
234235
content=ft.Column([
235-
ft.Text("To begin using this Chat Interface, an LLM API key or Source (Ollama) must be configured in the settings for one of the supported LLMs.", size=20, color=ft.colors.GREY, text_align=ft.TextAlign.CENTER),
236+
ft.Text("To begin using this Chat Interface, a LLM API key or local source (Ollama) must be configured in the settings for one of the supported LLM providers.", size=20, color=ft.colors.GREY, text_align=ft.TextAlign.CENTER),
236237
], alignment="center", horizontal_alignment="center", spacing=0, expand=True), expand=True, padding=ft.padding.only(0,0,0,150), alignment=ft.alignment.center)
237238

238239
# About content
@@ -534,6 +535,7 @@ def chatwindow(self):
534535
content=(self.threads[self.active_thread] if self.threads[self.active_thread].active else self.default) if self.llm_configured() else self.configure,
535536
padding=0,
536537
expand=True,
538+
alignment=ft.alignment.top_center
537539
),
538540
ft.Row([
539541
ft.Stack([
@@ -567,7 +569,7 @@ def chatwindow(self):
567569
expand=True,
568570
clip_behavior=ft.ClipBehavior.ANTI_ALIAS,
569571
)
570-
], expand=True, alignment=ft.alignment.bottom_center, spacing=0 ),
572+
], expand=True, alignment=ft.alignment.bottom_center, spacing=0),
571573
],
572574
)
573575

src/subconscious.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def splash_screen(self):
221221
return ft.Container(
222222
content=ft.Row([
223223
ft.Column([
224-
ft.Image(src="./src/assets/logo.png", width=100, height=100),
224+
ft.Image(src="./src/assets/logo.png", width=100, height=100, color=ft.colors.PRIMARY),
225225
ft.Text("Subconscious", size=25, color=ft.colors.PRIMARY),
226226
], alignment="center", horizontal_alignment="center", spacing=0, expand=True),
227227
], alignment="center", vertical_alignment="center", spacing=0, expand=True),

0 commit comments

Comments
 (0)