Spaces:
Paused
Paused
frdel commited on
Commit ·
8d90f44
1
Parent(s): 6166c15
console print edits for docker
Browse files- initialize.py +0 -4
- preload.py +3 -2
- prepare.py +5 -3
- python/helpers/attachment_manager.py +4 -2
- python/helpers/cloudflare_tunnel.py +8 -7
- python/helpers/docker.py +6 -6
- python/helpers/dotenv.py +3 -2
- python/helpers/file_browser.py +5 -4
- python/helpers/knowledge_import.py +4 -3
- python/helpers/memory.py +4 -2
- python/helpers/print_style.py +4 -0
- python/helpers/process.py +3 -2
- python/helpers/shell_ssh.py +2 -1
- python/helpers/whisper.py +2 -1
- run_cli.py +2 -2
- run_ui.py +24 -18
initialize.py
CHANGED
|
@@ -84,16 +84,12 @@ def args_override(config):
|
|
| 84 |
# conversion based on type of config[key]
|
| 85 |
if isinstance(getattr(config, key), bool):
|
| 86 |
value = value.lower().strip() == "true"
|
| 87 |
-
print("bool", value)
|
| 88 |
elif isinstance(getattr(config, key), int):
|
| 89 |
value = int(value)
|
| 90 |
-
print("int", value)
|
| 91 |
elif isinstance(getattr(config, key), float):
|
| 92 |
value = float(value)
|
| 93 |
-
print("float", value)
|
| 94 |
elif isinstance(getattr(config, key), str):
|
| 95 |
value = str(value)
|
| 96 |
-
print("str", value)
|
| 97 |
else:
|
| 98 |
raise Exception(
|
| 99 |
f"Unsupported argument type of '{key}': {type(getattr(config, key))}"
|
|
|
|
| 84 |
# conversion based on type of config[key]
|
| 85 |
if isinstance(getattr(config, key), bool):
|
| 86 |
value = value.lower().strip() == "true"
|
|
|
|
| 87 |
elif isinstance(getattr(config, key), int):
|
| 88 |
value = int(value)
|
|
|
|
| 89 |
elif isinstance(getattr(config, key), float):
|
| 90 |
value = float(value)
|
|
|
|
| 91 |
elif isinstance(getattr(config, key), str):
|
| 92 |
value = str(value)
|
|
|
|
| 93 |
else:
|
| 94 |
raise Exception(
|
| 95 |
f"Unsupported argument type of '{key}': {type(getattr(config, key))}"
|
preload.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
import asyncio
|
| 2 |
from python.helpers import runtime, whisper, settings
|
|
|
|
| 3 |
|
| 4 |
-
print("Running preload...")
|
| 5 |
runtime.initialize()
|
| 6 |
|
| 7 |
|
|
@@ -14,7 +15,7 @@ async def preload():
|
|
| 14 |
|
| 15 |
return asyncio.gather(*tasks, return_exceptions=True)
|
| 16 |
except Exception as e:
|
| 17 |
-
print(f"Error in preload: {e}")
|
| 18 |
|
| 19 |
|
| 20 |
# preload transcription model
|
|
|
|
| 1 |
import asyncio
|
| 2 |
from python.helpers import runtime, whisper, settings
|
| 3 |
+
from python.helpers.print_style import PrintStyle
|
| 4 |
|
| 5 |
+
PrintStyle().print("Running preload...")
|
| 6 |
runtime.initialize()
|
| 7 |
|
| 8 |
|
|
|
|
| 15 |
|
| 16 |
return asyncio.gather(*tasks, return_exceptions=True)
|
| 17 |
except Exception as e:
|
| 18 |
+
PrintStyle().print(f"Error in preload: {e}")
|
| 19 |
|
| 20 |
|
| 21 |
# preload transcription model
|
prepare.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
| 1 |
from python.helpers import dotenv, runtime, settings
|
| 2 |
import string
|
| 3 |
import random
|
|
|
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
try:
|
| 8 |
|
|
@@ -12,8 +14,8 @@ try:
|
|
| 12 |
root_pass = dotenv.get_dotenv_value(dotenv.KEY_ROOT_PASSWORD)
|
| 13 |
if not root_pass:
|
| 14 |
root_pass = "".join(random.choices(string.ascii_letters + string.digits, k=32))
|
| 15 |
-
|
| 16 |
settings.set_root_password(root_pass)
|
| 17 |
|
| 18 |
except Exception as e:
|
| 19 |
-
|
|
|
|
| 1 |
from python.helpers import dotenv, runtime, settings
|
| 2 |
import string
|
| 3 |
import random
|
| 4 |
+
from python.helpers.print_style import PrintStyle
|
| 5 |
|
| 6 |
+
|
| 7 |
+
PrintStyle.standard("Preparing environment...")
|
| 8 |
|
| 9 |
try:
|
| 10 |
|
|
|
|
| 14 |
root_pass = dotenv.get_dotenv_value(dotenv.KEY_ROOT_PASSWORD)
|
| 15 |
if not root_pass:
|
| 16 |
root_pass = "".join(random.choices(string.ascii_letters + string.digits, k=32))
|
| 17 |
+
PrintStyle.standard("Changing root password...")
|
| 18 |
settings.set_root_password(root_pass)
|
| 19 |
|
| 20 |
except Exception as e:
|
| 21 |
+
PrintStyle.error(f"Error in preload: {e}")
|
python/helpers/attachment_manager.py
CHANGED
|
@@ -5,6 +5,8 @@ from PIL import Image
|
|
| 5 |
from typing import Dict, List, Optional, Tuple
|
| 6 |
from werkzeug.utils import secure_filename
|
| 7 |
|
|
|
|
|
|
|
| 8 |
class AttachmentManager:
|
| 9 |
ALLOWED_EXTENSIONS = {
|
| 10 |
'image': {'jpg', 'jpeg', 'png', 'bmp'},
|
|
@@ -66,7 +68,7 @@ class AttachmentManager:
|
|
| 66 |
return file_path, metadata
|
| 67 |
|
| 68 |
except Exception as e:
|
| 69 |
-
|
| 70 |
return None, {} # type: ignore
|
| 71 |
|
| 72 |
def generate_image_preview(self, image_path: str, max_size: int = 800) -> Optional[str]:
|
|
@@ -86,6 +88,6 @@ class AttachmentManager:
|
|
| 86 |
# Convert to base64
|
| 87 |
return base64.b64encode(buffer.getvalue()).decode('utf-8')
|
| 88 |
except Exception as e:
|
| 89 |
-
|
| 90 |
return None
|
| 91 |
|
|
|
|
| 5 |
from typing import Dict, List, Optional, Tuple
|
| 6 |
from werkzeug.utils import secure_filename
|
| 7 |
|
| 8 |
+
from python.helpers.print_style import PrintStyle
|
| 9 |
+
|
| 10 |
class AttachmentManager:
|
| 11 |
ALLOWED_EXTENSIONS = {
|
| 12 |
'image': {'jpg', 'jpeg', 'png', 'bmp'},
|
|
|
|
| 68 |
return file_path, metadata
|
| 69 |
|
| 70 |
except Exception as e:
|
| 71 |
+
PrintStyle.error(f"Error saving file {filename}: {e}")
|
| 72 |
return None, {} # type: ignore
|
| 73 |
|
| 74 |
def generate_image_preview(self, image_path: str, max_size: int = 800) -> Optional[str]:
|
|
|
|
| 88 |
# Convert to base64
|
| 89 |
return base64.b64encode(buffer.getvalue()).decode('utf-8')
|
| 90 |
except Exception as e:
|
| 91 |
+
PrintStyle.error(f"Error generating preview for {image_path}: {e}")
|
| 92 |
return None
|
| 93 |
|
python/helpers/cloudflare_tunnel.py
CHANGED
|
@@ -4,6 +4,7 @@ import requests
|
|
| 4 |
import subprocess
|
| 5 |
import threading
|
| 6 |
from python.helpers import files
|
|
|
|
| 7 |
|
| 8 |
class CloudflareTunnel:
|
| 9 |
def __init__(self, port: int):
|
|
@@ -41,7 +42,7 @@ class CloudflareTunnel:
|
|
| 41 |
download_url = f"{base_url}{download_file}"
|
| 42 |
download_path = files.get_abs_path(self.bin_dir, download_file)
|
| 43 |
|
| 44 |
-
print(f"\nDownloading cloudflared from: {download_url}")
|
| 45 |
response = requests.get(download_url, stream=True)
|
| 46 |
if response.status_code != 200:
|
| 47 |
raise RuntimeError(f"Failed to download cloudflared: {response.status_code}")
|
|
@@ -77,7 +78,7 @@ class CloudflareTunnel:
|
|
| 77 |
download_url = f"{base_url}{download_file}"
|
| 78 |
download_path = files.get_abs_path(self.bin_dir, download_file)
|
| 79 |
|
| 80 |
-
print(f"\nDownloading cloudflared from: {download_url}")
|
| 81 |
response = requests.get(download_url, stream=True)
|
| 82 |
if response.status_code != 200:
|
| 83 |
raise RuntimeError(f"Failed to download cloudflared: {response.status_code}")
|
|
@@ -113,9 +114,9 @@ class CloudflareTunnel:
|
|
| 113 |
start = line.find("https://")
|
| 114 |
end = line.find("trycloudflare.com") + len("trycloudflare.com")
|
| 115 |
self.tunnel_url = line[start:end].strip()
|
| 116 |
-
print("\n=== Cloudflare Tunnel URL ===")
|
| 117 |
-
print(f"URL: {self.tunnel_url}")
|
| 118 |
-
print("============================\n")
|
| 119 |
return
|
| 120 |
|
| 121 |
def start(self):
|
|
@@ -123,7 +124,7 @@ class CloudflareTunnel:
|
|
| 123 |
if not self.cloudflared_path:
|
| 124 |
self.download_cloudflared()
|
| 125 |
|
| 126 |
-
print("\nStarting Cloudflare tunnel...")
|
| 127 |
# Start tunnel process
|
| 128 |
self.tunnel_process = subprocess.Popen(
|
| 129 |
[
|
|
@@ -149,7 +150,7 @@ class CloudflareTunnel:
|
|
| 149 |
"""Stops the cloudflare tunnel"""
|
| 150 |
self._stop_event.set()
|
| 151 |
if self.tunnel_process:
|
| 152 |
-
print("\nStopping Cloudflare tunnel...")
|
| 153 |
self.tunnel_process.terminate()
|
| 154 |
self.tunnel_process.wait()
|
| 155 |
self.tunnel_process = None
|
|
|
|
| 4 |
import subprocess
|
| 5 |
import threading
|
| 6 |
from python.helpers import files
|
| 7 |
+
from python.helpers.print_style import PrintStyle
|
| 8 |
|
| 9 |
class CloudflareTunnel:
|
| 10 |
def __init__(self, port: int):
|
|
|
|
| 42 |
download_url = f"{base_url}{download_file}"
|
| 43 |
download_path = files.get_abs_path(self.bin_dir, download_file)
|
| 44 |
|
| 45 |
+
PrintStyle().print(f"\nDownloading cloudflared from: {download_url}")
|
| 46 |
response = requests.get(download_url, stream=True)
|
| 47 |
if response.status_code != 200:
|
| 48 |
raise RuntimeError(f"Failed to download cloudflared: {response.status_code}")
|
|
|
|
| 78 |
download_url = f"{base_url}{download_file}"
|
| 79 |
download_path = files.get_abs_path(self.bin_dir, download_file)
|
| 80 |
|
| 81 |
+
PrintStyle().print(f"\nDownloading cloudflared from: {download_url}")
|
| 82 |
response = requests.get(download_url, stream=True)
|
| 83 |
if response.status_code != 200:
|
| 84 |
raise RuntimeError(f"Failed to download cloudflared: {response.status_code}")
|
|
|
|
| 114 |
start = line.find("https://")
|
| 115 |
end = line.find("trycloudflare.com") + len("trycloudflare.com")
|
| 116 |
self.tunnel_url = line[start:end].strip()
|
| 117 |
+
PrintStyle().print("\n=== Cloudflare Tunnel URL ===")
|
| 118 |
+
PrintStyle().print(f"URL: {self.tunnel_url}")
|
| 119 |
+
PrintStyle().print("============================\n")
|
| 120 |
return
|
| 121 |
|
| 122 |
def start(self):
|
|
|
|
| 124 |
if not self.cloudflared_path:
|
| 125 |
self.download_cloudflared()
|
| 126 |
|
| 127 |
+
PrintStyle().print("\nStarting Cloudflare tunnel...")
|
| 128 |
# Start tunnel process
|
| 129 |
self.tunnel_process = subprocess.Popen(
|
| 130 |
[
|
|
|
|
| 150 |
"""Stops the cloudflare tunnel"""
|
| 151 |
self._stop_event.set()
|
| 152 |
if self.tunnel_process:
|
| 153 |
+
PrintStyle().print("\nStopping Cloudflare tunnel...")
|
| 154 |
self.tunnel_process.terminate()
|
| 155 |
self.tunnel_process.wait()
|
| 156 |
self.tunnel_process = None
|
python/helpers/docker.py
CHANGED
|
@@ -38,10 +38,10 @@ class DockerContainerManager:
|
|
| 38 |
try:
|
| 39 |
self.container.stop()
|
| 40 |
self.container.remove()
|
| 41 |
-
|
| 42 |
if self.logger: self.logger.log(type="info", content=f"Stopped and removed the container: {self.container.id}")
|
| 43 |
except Exception as e:
|
| 44 |
-
|
| 45 |
if self.logger: self.logger.log(type="error", content=f"Failed to stop and remove the container: {e}")
|
| 46 |
|
| 47 |
def get_image_containers(self):
|
|
@@ -72,7 +72,7 @@ class DockerContainerManager:
|
|
| 72 |
|
| 73 |
if existing_container:
|
| 74 |
if existing_container.status != 'running':
|
| 75 |
-
|
| 76 |
if self.logger: self.logger.log(type="info", content=f"Starting existing container: {self.name} for safe code execution...", temp=True)
|
| 77 |
|
| 78 |
existing_container.start()
|
|
@@ -81,9 +81,9 @@ class DockerContainerManager:
|
|
| 81 |
|
| 82 |
else:
|
| 83 |
self.container = existing_container
|
| 84 |
-
#
|
| 85 |
else:
|
| 86 |
-
|
| 87 |
if self.logger: self.logger.log(type="info", content=f"Initializing docker container {self.name} for safe code execution...", temp=True)
|
| 88 |
|
| 89 |
self.container = self.client.containers.run(
|
|
@@ -94,6 +94,6 @@ class DockerContainerManager:
|
|
| 94 |
volumes=self.volumes, # type: ignore
|
| 95 |
)
|
| 96 |
# atexit.register(self.cleanup_container)
|
| 97 |
-
|
| 98 |
if self.logger: self.logger.log(type="info", content=f"Started container with ID: {self.container.id}")
|
| 99 |
time.sleep(5) # this helps to get SSH ready
|
|
|
|
| 38 |
try:
|
| 39 |
self.container.stop()
|
| 40 |
self.container.remove()
|
| 41 |
+
PrintStyle.standard(f"Stopped and removed the container: {self.container.id}")
|
| 42 |
if self.logger: self.logger.log(type="info", content=f"Stopped and removed the container: {self.container.id}")
|
| 43 |
except Exception as e:
|
| 44 |
+
PrintStyle.error(f"Failed to stop and remove the container: {e}")
|
| 45 |
if self.logger: self.logger.log(type="error", content=f"Failed to stop and remove the container: {e}")
|
| 46 |
|
| 47 |
def get_image_containers(self):
|
|
|
|
| 72 |
|
| 73 |
if existing_container:
|
| 74 |
if existing_container.status != 'running':
|
| 75 |
+
PrintStyle.standard(f"Starting existing container: {self.name} for safe code execution...")
|
| 76 |
if self.logger: self.logger.log(type="info", content=f"Starting existing container: {self.name} for safe code execution...", temp=True)
|
| 77 |
|
| 78 |
existing_container.start()
|
|
|
|
| 81 |
|
| 82 |
else:
|
| 83 |
self.container = existing_container
|
| 84 |
+
# PrintStyle.standard(f"Container with name '{self.name}' is already running with ID: {existing_container.id}")
|
| 85 |
else:
|
| 86 |
+
PrintStyle.standard(f"Initializing docker container {self.name} for safe code execution...")
|
| 87 |
if self.logger: self.logger.log(type="info", content=f"Initializing docker container {self.name} for safe code execution...", temp=True)
|
| 88 |
|
| 89 |
self.container = self.client.containers.run(
|
|
|
|
| 94 |
volumes=self.volumes, # type: ignore
|
| 95 |
)
|
| 96 |
# atexit.register(self.cleanup_container)
|
| 97 |
+
PrintStyle.standard(f"Started container with ID: {self.container.id}")
|
| 98 |
if self.logger: self.logger.log(type="info", content=f"Started container with ID: {self.container.id}")
|
| 99 |
time.sleep(5) # this helps to get SSH ready
|
python/helpers/dotenv.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import re
|
|
|
|
| 3 |
|
| 4 |
from .files import get_abs_path
|
| 5 |
from dotenv import load_dotenv as _load_dotenv
|
|
@@ -16,9 +17,9 @@ def load_dotenv():
|
|
| 16 |
def get_dotenv_file_path():
|
| 17 |
return get_abs_path(".env")
|
| 18 |
|
| 19 |
-
def get_dotenv_value(key: str):
|
| 20 |
# load_dotenv()
|
| 21 |
-
return os.getenv(key)
|
| 22 |
|
| 23 |
def save_dotenv_value(key: str, value: str):
|
| 24 |
if value is None:
|
|
|
|
| 1 |
import os
|
| 2 |
import re
|
| 3 |
+
from typing import Any
|
| 4 |
|
| 5 |
from .files import get_abs_path
|
| 6 |
from dotenv import load_dotenv as _load_dotenv
|
|
|
|
| 17 |
def get_dotenv_file_path():
|
| 18 |
return get_abs_path(".env")
|
| 19 |
|
| 20 |
+
def get_dotenv_value(key: str, default: Any = None):
|
| 21 |
# load_dotenv()
|
| 22 |
+
return os.getenv(key, default)
|
| 23 |
|
| 24 |
def save_dotenv_value(key: str, value: str):
|
| 25 |
if value is None:
|
python/helpers/file_browser.py
CHANGED
|
@@ -8,6 +8,7 @@ from werkzeug.utils import secure_filename
|
|
| 8 |
from datetime import datetime
|
| 9 |
|
| 10 |
from python.helpers import files, runtime
|
|
|
|
| 11 |
|
| 12 |
class FileBrowser:
|
| 13 |
ALLOWED_EXTENSIONS = {
|
|
@@ -58,13 +59,13 @@ class FileBrowser:
|
|
| 58 |
else:
|
| 59 |
failed.append(file.filename)
|
| 60 |
except Exception as e:
|
| 61 |
-
|
| 62 |
failed.append(file.filename)
|
| 63 |
|
| 64 |
return successful, failed
|
| 65 |
|
| 66 |
except Exception as e:
|
| 67 |
-
|
| 68 |
return successful, failed
|
| 69 |
|
| 70 |
def delete_file(self, file_path: str) -> bool:
|
|
@@ -85,7 +86,7 @@ class FileBrowser:
|
|
| 85 |
return False
|
| 86 |
|
| 87 |
except Exception as e:
|
| 88 |
-
|
| 89 |
return False
|
| 90 |
|
| 91 |
def _is_allowed_file(self, filename: str, file) -> bool:
|
|
@@ -160,7 +161,7 @@ class FileBrowser:
|
|
| 160 |
}
|
| 161 |
|
| 162 |
except Exception as e:
|
| 163 |
-
|
| 164 |
return {"entries": [], "current_path": "", "parent_path": ""}
|
| 165 |
|
| 166 |
def get_full_path(self, file_path: str, allow_dir: bool = False) -> str:
|
|
|
|
| 8 |
from datetime import datetime
|
| 9 |
|
| 10 |
from python.helpers import files, runtime
|
| 11 |
+
from python.helpers.print_style import PrintStyle
|
| 12 |
|
| 13 |
class FileBrowser:
|
| 14 |
ALLOWED_EXTENSIONS = {
|
|
|
|
| 59 |
else:
|
| 60 |
failed.append(file.filename)
|
| 61 |
except Exception as e:
|
| 62 |
+
PrintStyle.error(f"Error saving file {file.filename}: {e}")
|
| 63 |
failed.append(file.filename)
|
| 64 |
|
| 65 |
return successful, failed
|
| 66 |
|
| 67 |
except Exception as e:
|
| 68 |
+
PrintStyle.error(f"Error in save_files: {e}")
|
| 69 |
return successful, failed
|
| 70 |
|
| 71 |
def delete_file(self, file_path: str) -> bool:
|
|
|
|
| 86 |
return False
|
| 87 |
|
| 88 |
except Exception as e:
|
| 89 |
+
PrintStyle.error(f"Error deleting {file_path}: {e}")
|
| 90 |
return False
|
| 91 |
|
| 92 |
def _is_allowed_file(self, filename: str, file) -> bool:
|
|
|
|
| 161 |
}
|
| 162 |
|
| 163 |
except Exception as e:
|
| 164 |
+
PrintStyle.error(f"Error reading directory: {e}")
|
| 165 |
return {"entries": [], "current_path": "", "parent_path": ""}
|
| 166 |
|
| 167 |
def get_full_path(self, file_path: str, allow_dir: bool = False) -> str:
|
python/helpers/knowledge_import.py
CHANGED
|
@@ -13,6 +13,7 @@ from langchain_community.document_loaders import (
|
|
| 13 |
)
|
| 14 |
from python.helpers import files
|
| 15 |
from python.helpers.log import LogItem
|
|
|
|
| 16 |
|
| 17 |
text_loader_kwargs = {"autodetect_encoding": True}
|
| 18 |
|
|
@@ -70,7 +71,7 @@ def load_knowledge(
|
|
| 70 |
kn_files = [f for f in kn_files if os.path.isfile(f)]
|
| 71 |
|
| 72 |
if kn_files:
|
| 73 |
-
|
| 74 |
f"Found {len(kn_files)} knowledge files in {knowledge_dir}, processing..."
|
| 75 |
)
|
| 76 |
if log_item:
|
|
@@ -108,7 +109,7 @@ def load_knowledge(
|
|
| 108 |
doc.metadata = {**doc.metadata, **metadata}
|
| 109 |
cnt_files += 1
|
| 110 |
cnt_docs += len(file_data["documents"])
|
| 111 |
-
#
|
| 112 |
|
| 113 |
# Update the index
|
| 114 |
index[file_key] = file_data # type: ignore
|
|
@@ -118,7 +119,7 @@ def load_knowledge(
|
|
| 118 |
if not file_data.get("state", ""):
|
| 119 |
index[file_key]["state"] = "removed"
|
| 120 |
|
| 121 |
-
|
| 122 |
if log_item:
|
| 123 |
log_item.stream(
|
| 124 |
progress=f"\nProcessed {cnt_docs} documents from {cnt_files} files."
|
|
|
|
| 13 |
)
|
| 14 |
from python.helpers import files
|
| 15 |
from python.helpers.log import LogItem
|
| 16 |
+
from python.helpers.print_style import PrintStyle
|
| 17 |
|
| 18 |
text_loader_kwargs = {"autodetect_encoding": True}
|
| 19 |
|
|
|
|
| 71 |
kn_files = [f for f in kn_files if os.path.isfile(f)]
|
| 72 |
|
| 73 |
if kn_files:
|
| 74 |
+
PrintStyle.standard(
|
| 75 |
f"Found {len(kn_files)} knowledge files in {knowledge_dir}, processing..."
|
| 76 |
)
|
| 77 |
if log_item:
|
|
|
|
| 109 |
doc.metadata = {**doc.metadata, **metadata}
|
| 110 |
cnt_files += 1
|
| 111 |
cnt_docs += len(file_data["documents"])
|
| 112 |
+
# PrintStyle.standard(f"Imported {len(file_data['documents'])} documents from {file_path}")
|
| 113 |
|
| 114 |
# Update the index
|
| 115 |
index[file_key] = file_data # type: ignore
|
|
|
|
| 119 |
if not file_data.get("state", ""):
|
| 120 |
index[file_key]["state"] = "removed"
|
| 121 |
|
| 122 |
+
PrintStyle.standard(f"Processed {cnt_docs} documents from {cnt_files} files.")
|
| 123 |
if log_item:
|
| 124 |
log_item.stream(
|
| 125 |
progress=f"\nProcessed {cnt_docs} documents from {cnt_files} files."
|
python/helpers/memory.py
CHANGED
|
@@ -13,6 +13,8 @@ from langchain_community.vectorstores.utils import (
|
|
| 13 |
import os, json
|
| 14 |
|
| 15 |
import numpy as np
|
|
|
|
|
|
|
| 16 |
from . import files
|
| 17 |
from langchain_core.documents import Document
|
| 18 |
import uuid
|
|
@@ -78,7 +80,7 @@ class Memory:
|
|
| 78 |
in_memory=False,
|
| 79 |
) -> MyFaiss:
|
| 80 |
|
| 81 |
-
|
| 82 |
|
| 83 |
if log_item:
|
| 84 |
log_item.stream(progress="\nInitializing VectorDB")
|
|
@@ -312,7 +314,7 @@ class Memory:
|
|
| 312 |
try:
|
| 313 |
return eval(condition, {}, data)
|
| 314 |
except Exception as e:
|
| 315 |
-
#
|
| 316 |
return False
|
| 317 |
|
| 318 |
return comparator
|
|
|
|
| 13 |
import os, json
|
| 14 |
|
| 15 |
import numpy as np
|
| 16 |
+
|
| 17 |
+
from python.helpers.print_style import PrintStyle
|
| 18 |
from . import files
|
| 19 |
from langchain_core.documents import Document
|
| 20 |
import uuid
|
|
|
|
| 80 |
in_memory=False,
|
| 81 |
) -> MyFaiss:
|
| 82 |
|
| 83 |
+
PrintStyle.standard("Initializing VectorDB...")
|
| 84 |
|
| 85 |
if log_item:
|
| 86 |
log_item.stream(progress="\nInitializing VectorDB")
|
|
|
|
| 314 |
try:
|
| 315 |
return eval(condition, {}, data)
|
| 316 |
except Exception as e:
|
| 317 |
+
# PrintStyle.error(f"Error evaluating condition: {e}")
|
| 318 |
return False
|
| 319 |
|
| 320 |
return comparator
|
python/helpers/print_style.py
CHANGED
|
@@ -117,6 +117,10 @@ class PrintStyle:
|
|
| 117 |
lines = sys.stdin.readlines()
|
| 118 |
return bool(lines) and not lines[-1].strip()
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
@staticmethod
|
| 121 |
def hint(text:str):
|
| 122 |
PrintStyle(font_color="#6C3483", padding=True).print("Hint: "+text)
|
|
|
|
| 117 |
lines = sys.stdin.readlines()
|
| 118 |
return bool(lines) and not lines[-1].strip()
|
| 119 |
|
| 120 |
+
@staticmethod
|
| 121 |
+
def standard(text:str):
|
| 122 |
+
PrintStyle().print(text)
|
| 123 |
+
|
| 124 |
@staticmethod
|
| 125 |
def hint(text:str):
|
| 126 |
PrintStyle(font_color="#6C3483", padding=True).print("Hint: "+text)
|
python/helpers/process.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
from python.helpers import runtime
|
|
|
|
| 4 |
|
| 5 |
_server = None
|
| 6 |
|
|
@@ -26,10 +27,10 @@ def reload():
|
|
| 26 |
restart_process()
|
| 27 |
|
| 28 |
def restart_process():
|
| 29 |
-
|
| 30 |
python = sys.executable
|
| 31 |
os.execv(python, [python] + sys.argv)
|
| 32 |
|
| 33 |
def exit_process():
|
| 34 |
-
|
| 35 |
sys.exit(0)
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
from python.helpers import runtime
|
| 4 |
+
from python.helpers.print_style import PrintStyle
|
| 5 |
|
| 6 |
_server = None
|
| 7 |
|
|
|
|
| 27 |
restart_process()
|
| 28 |
|
| 29 |
def restart_process():
|
| 30 |
+
PrintStyle.standard("Restarting process...")
|
| 31 |
python = sys.executable
|
| 32 |
os.execv(python, [python] + sys.argv)
|
| 33 |
|
| 34 |
def exit_process():
|
| 35 |
+
PrintStyle.standard("Exiting process...")
|
| 36 |
sys.exit(0)
|
python/helpers/shell_ssh.py
CHANGED
|
@@ -4,6 +4,7 @@ import time
|
|
| 4 |
import re
|
| 5 |
from typing import Tuple
|
| 6 |
from python.helpers.log import Log
|
|
|
|
| 7 |
from python.helpers.strings import calculate_valid_match_lengths
|
| 8 |
|
| 9 |
|
|
@@ -51,7 +52,7 @@ class SSHInteractiveSession:
|
|
| 51 |
except Exception as e:
|
| 52 |
errors += 1
|
| 53 |
if errors < 3:
|
| 54 |
-
|
| 55 |
self.logger.log(
|
| 56 |
type="info",
|
| 57 |
content=f"SSH Connection attempt {errors}...",
|
|
|
|
| 4 |
import re
|
| 5 |
from typing import Tuple
|
| 6 |
from python.helpers.log import Log
|
| 7 |
+
from python.helpers.print_style import PrintStyle
|
| 8 |
from python.helpers.strings import calculate_valid_match_lengths
|
| 9 |
|
| 10 |
|
|
|
|
| 52 |
except Exception as e:
|
| 53 |
errors += 1
|
| 54 |
if errors < 3:
|
| 55 |
+
PrintStyle.standard(f"SSH Connection attempt {errors}...")
|
| 56 |
self.logger.log(
|
| 57 |
type="info",
|
| 58 |
content=f"SSH Connection attempt {errors}...",
|
python/helpers/whisper.py
CHANGED
|
@@ -4,6 +4,7 @@ import whisper
|
|
| 4 |
import tempfile
|
| 5 |
import asyncio
|
| 6 |
from python.helpers import runtime, rfc, settings
|
|
|
|
| 7 |
|
| 8 |
# Suppress FutureWarning from torch.load
|
| 9 |
warnings.filterwarnings("ignore", category=FutureWarning)
|
|
@@ -28,7 +29,7 @@ async def _preload(model_name:str):
|
|
| 28 |
try:
|
| 29 |
is_updating_model = True
|
| 30 |
if not _model or _model_name != model_name:
|
| 31 |
-
|
| 32 |
_model = whisper.load_model(model_name)
|
| 33 |
_model_name = model_name
|
| 34 |
finally:
|
|
|
|
| 4 |
import tempfile
|
| 5 |
import asyncio
|
| 6 |
from python.helpers import runtime, rfc, settings
|
| 7 |
+
from python.helpers.print_style import PrintStyle
|
| 8 |
|
| 9 |
# Suppress FutureWarning from torch.load
|
| 10 |
warnings.filterwarnings("ignore", category=FutureWarning)
|
|
|
|
| 29 |
try:
|
| 30 |
is_updating_model = True
|
| 31 |
if not _model or _model_name != model_name:
|
| 32 |
+
PrintStyle.standard(f"Loading Whisper model: {model_name}")
|
| 33 |
_model = whisper.load_model(model_name)
|
| 34 |
_model_name = model_name
|
| 35 |
finally:
|
run_cli.py
CHANGED
|
@@ -96,7 +96,7 @@ def timeout_input(prompt, timeout=10):
|
|
| 96 |
|
| 97 |
def run():
|
| 98 |
global context
|
| 99 |
-
|
| 100 |
|
| 101 |
#load env vars
|
| 102 |
load_dotenv()
|
|
@@ -112,5 +112,5 @@ def run():
|
|
| 112 |
asyncio.run(chat(context))
|
| 113 |
|
| 114 |
if __name__ == "__main__":
|
| 115 |
-
|
| 116 |
run()
|
|
|
|
| 96 |
|
| 97 |
def run():
|
| 98 |
global context
|
| 99 |
+
PrintStyle.standard("Initializing framework...")
|
| 100 |
|
| 101 |
#load env vars
|
| 102 |
load_dotenv()
|
|
|
|
| 112 |
asyncio.run(chat(context))
|
| 113 |
|
| 114 |
if __name__ == "__main__":
|
| 115 |
+
PrintStyle.standard("\n\n!!! run_cli.py is now discontinued. run_ui.py serves as both UI and API endpoint !!!\n\n")
|
| 116 |
run()
|
run_ui.py
CHANGED
|
@@ -3,12 +3,13 @@ import os
|
|
| 3 |
import threading
|
| 4 |
from flask import Flask, request, Response
|
| 5 |
from flask_basicauth import BasicAuth
|
| 6 |
-
from python.helpers import files, git
|
| 7 |
from python.helpers.files import get_abs_path
|
| 8 |
from python.helpers import persist_chat, runtime, dotenv, process
|
| 9 |
from python.helpers.cloudflare_tunnel import CloudflareTunnel
|
| 10 |
from python.helpers.extract_tools import load_classes_from_folder
|
| 11 |
from python.helpers.api import ApiHandler
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
# initialize the internal Flask server
|
|
@@ -54,7 +55,7 @@ async def serve_index():
|
|
| 54 |
|
| 55 |
|
| 56 |
def run():
|
| 57 |
-
print("Initializing framework...")
|
| 58 |
|
| 59 |
# Suppress only request logs but keep the startup messages
|
| 60 |
from werkzeug.serving import WSGIRequestHandler
|
|
@@ -65,25 +66,29 @@ def run():
|
|
| 65 |
pass # Override to suppress request logging
|
| 66 |
|
| 67 |
# Get configuration from environment
|
| 68 |
-
port = runtime.get_arg("port") or int(
|
| 69 |
-
host = runtime.get_arg("host") or
|
| 70 |
-
use_cloudflare = (
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
)
|
| 74 |
|
| 75 |
-
# Initialize and start Cloudflare tunnel if enabled
|
| 76 |
tunnel = None
|
| 77 |
-
if use_cloudflare and port:
|
| 78 |
-
try:
|
| 79 |
-
tunnel = CloudflareTunnel(port)
|
| 80 |
-
tunnel.start()
|
| 81 |
-
except Exception as e:
|
| 82 |
-
print(f"Failed to start Cloudflare tunnel: {e}")
|
| 83 |
-
print("Continuing without tunnel...")
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
server = None
|
| 89 |
|
|
@@ -123,4 +128,5 @@ def run():
|
|
| 123 |
# run the internal server
|
| 124 |
if __name__ == "__main__":
|
| 125 |
runtime.initialize()
|
|
|
|
| 126 |
run()
|
|
|
|
| 3 |
import threading
|
| 4 |
from flask import Flask, request, Response
|
| 5 |
from flask_basicauth import BasicAuth
|
| 6 |
+
from python.helpers import errors, files, git
|
| 7 |
from python.helpers.files import get_abs_path
|
| 8 |
from python.helpers import persist_chat, runtime, dotenv, process
|
| 9 |
from python.helpers.cloudflare_tunnel import CloudflareTunnel
|
| 10 |
from python.helpers.extract_tools import load_classes_from_folder
|
| 11 |
from python.helpers.api import ApiHandler
|
| 12 |
+
from python.helpers.print_style import PrintStyle
|
| 13 |
|
| 14 |
|
| 15 |
# initialize the internal Flask server
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
def run():
|
| 58 |
+
PrintStyle().print("Initializing framework...")
|
| 59 |
|
| 60 |
# Suppress only request logs but keep the startup messages
|
| 61 |
from werkzeug.serving import WSGIRequestHandler
|
|
|
|
| 66 |
pass # Override to suppress request logging
|
| 67 |
|
| 68 |
# Get configuration from environment
|
| 69 |
+
port = runtime.get_arg("port") or int(dotenv.get_dotenv_value("WEB_UI_PORT", 0)) or 5000
|
| 70 |
+
host = runtime.get_arg("host") or dotenv.get_dotenv_value("WEB_UI_HOST") or "localhost"
|
| 71 |
+
use_cloudflare = (runtime.get_arg("cloudflare_tunnel")
|
| 72 |
+
or dotenv.get_dotenv_value("USE_CLOUDFLARE", "false").lower()) == "true"
|
| 73 |
+
|
|
|
|
| 74 |
|
|
|
|
| 75 |
tunnel = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
try:
|
| 78 |
+
# Initialize and start Cloudflare tunnel if enabled
|
| 79 |
+
if use_cloudflare and port:
|
| 80 |
+
try:
|
| 81 |
+
tunnel = CloudflareTunnel(port)
|
| 82 |
+
tunnel.start()
|
| 83 |
+
except Exception as e:
|
| 84 |
+
PrintStyle().error(f"Failed to start Cloudflare tunnel: {e}")
|
| 85 |
+
PrintStyle().print("Continuing without tunnel...")
|
| 86 |
+
|
| 87 |
+
# initialize contexts from persisted chats
|
| 88 |
+
persist_chat.load_tmp_chats()
|
| 89 |
+
|
| 90 |
+
except Exception as e:
|
| 91 |
+
PrintStyle().error(errors.format_error(e))
|
| 92 |
|
| 93 |
server = None
|
| 94 |
|
|
|
|
| 128 |
# run the internal server
|
| 129 |
if __name__ == "__main__":
|
| 130 |
runtime.initialize()
|
| 131 |
+
dotenv.load_dotenv()
|
| 132 |
run()
|