Skip to content

Commit

Permalink
Minor visual adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Saporetti Junior committed Mar 20, 2024
1 parent 26676eb commit 05cab6b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
4 changes: 3 additions & 1 deletion src/main/askai/core/askai.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from threading import Thread
from typing import List, Optional

import nltk
import pause
from clitt.core.term.cursor import Cursor
from clitt.core.term.screen import Screen
Expand Down Expand Up @@ -175,12 +176,13 @@ def _splash(self) -> None:
def _startup(self) -> None:
"""Initialize the application."""
splash_thread: Thread = Thread(daemon=True, target=self._splash)
splash_thread.start()
if configs.is_speak:
recorder.setup()
configs.is_speak = recorder.input_device is not None
splash_thread.start()
if configs.is_speak:
AudioPlayer.INSTANCE.start_delay()
nltk.download("averaged_perceptron_tagger", quiet=True)
cache.set_cache_enable(self.cache_enabled)
cache.read_query_history()
askai_bus = AskAiEvents.get_bus(ASKAI_BUS_NAME)
Expand Down
25 changes: 12 additions & 13 deletions src/main/askai/core/component/summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@
Copyright·(c)·2024,·HSPyLib
"""
from askai.core.askai_events import AskAiEvents
from askai.core.askai_messages import msg
from askai.core.component.cache_service import PERSIST_DIR
from askai.core.model.summary_result import SummaryResult
from askai.core.support.langchain_support import lc_llm
from askai.core.support.utilities import hash_text
from askai.exception.exceptions import DocumentsNotFound
import logging as log
import os
from functools import lru_cache
from pathlib import Path
from typing import List, Optional, Tuple

from hspylib.core.metaclass.singleton import Singleton
from hspylib.core.tools.text_tools import ensure_endswith
from langchain.chains import RetrievalQA
from langchain_community.document_loaders import DirectoryLoader
from langchain_community.vectorstores.chroma import Chroma
from langchain_core.documents import Document
from langchain_text_splitters import RecursiveCharacterTextSplitter, TextSplitter
from pathlib import Path
from typing import List, Optional, Tuple

import logging as log
import nltk
import os
from askai.core.askai_events import AskAiEvents
from askai.core.askai_messages import msg
from askai.core.component.cache_service import PERSIST_DIR
from askai.core.model.summary_result import SummaryResult
from askai.core.support.langchain_support import lc_llm
from askai.core.support.utilities import hash_text
from askai.exception.exceptions import DocumentsNotFound


class Summarizer(metaclass=Singleton):
Expand All @@ -56,7 +56,6 @@ def exists(folder: str | Path, glob: str) -> bool:
return Path(f"{PERSIST_DIR}/{summary_hash}").exists()

def __init__(self):
nltk.download("averaged_perceptron_tagger")
self._retriever = None
self._folder = None
self._glob = None
Expand Down
30 changes: 15 additions & 15 deletions src/main/askai/core/support/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
import re

CHAT_ICONS = {
"": "%RED%",
"": "%BLUE%",
"": "%BLUE%",
"": "%BLUE%",
"": "%YELLOW%",
"": "%YELLOW%",
"": "%ORANGE%",
'': '\n\n%RED% Error: ',
'': '\n\n%BLUE% Hints & Tips: ',
'': '\n\n%BLUE% Analysis: ',
'': '\n\n%BLUE% Summary: ',
'': '\n\n%YELLOW% Joke: ',
'': '\n\n%YELLOW% Fun-Fact: ',
'': '\n\n%ORANGE% Advice: ',
}


Expand All @@ -50,19 +50,19 @@ def beautify(text: Any) -> str:
r'www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))'
r'[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})')
text = str(text)
text = re.sub(r"[Hh]ints?( and tips)?[-:\s]([ \n\t]*)", fr"{CHAT_ICONS['']}\1 Tips: ", text)
text = re.sub(r"[Aa]nalysis[-:\s]([ \n\t]*)", fr"{CHAT_ICONS['']}\1 Analysis: ", text)
text = re.sub(r"[Ss]ummary[-:\s]([ \n\t]*)", fr"{CHAT_ICONS['']}\1 Summary:", text)
text = re.sub(r"([Jj]oke( [Tt]ime)?)[-:\s]([ \n\t]*)", fr"{CHAT_ICONS['']}\1 Joke: ", text)
text = re.sub(r"[Ff]un [Ff]acts?[-:\s]([ \n\t]*)", fr"{CHAT_ICONS['']}\1 Fun Fact: ", text)
text = re.sub(r"[Aa]dvice[-:\s]([ \n\t]*)", fr"{CHAT_ICONS['']}\1 Advice: ", text)
text = re.sub(r"Errors?[-:\s]([ \n\t]*)", fr"%EL1%{CHAT_ICONS['']}\1 Error: ", text)
text = re.sub(r"Errors?[-:\s][ \n\t]+", CHAT_ICONS[''], text)
text = re.sub(r"[Hh]ints?( and tips)?[-:\s][ \n\t]+", CHAT_ICONS[''], text)
text = re.sub(r"[Aa]nalysis[-:\s][ \n\t]+", CHAT_ICONS[''], text)
text = re.sub(r"[Ss]ummary[-:\s][ \n\t]+", CHAT_ICONS[''], text)
text = re.sub(r"([Jj]oke( [Tt]ime)?)[-:\s][ \n\t]+", CHAT_ICONS[''], text)
text = re.sub(r"[Ff]un [Ff]acts?[-:\s][ \n\t]+", CHAT_ICONS[''], text)
text = re.sub(r"[Aa]dvice[-:\s][ \n\t]+", CHAT_ICONS[''], text)
text = re.sub(re_url, r'%CYAN% \1%GREEN%', text)
text = re.sub(r"^\n+", '', text, re.MULTILINE)
text = re.sub(r"\n{2,}", '\n\n', text, re.MULTILINE)
# fmt: on

return text.rstrip()
return text


def read_resource(base_dir: str, filename: str, file_ext: str = ".txt") -> str:
Expand Down

0 comments on commit 05cab6b

Please sign in to comment.