Skip to content

Commit

Permalink
raise error on encrypted files
Browse files Browse the repository at this point in the history
  • Loading branch information
mmz-001 committed Jul 6, 2023
1 parent 8bddd3b commit 0a2868d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
6 changes: 5 additions & 1 deletion knowledge_gpt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
is_query_valid,
is_file_valid,
is_open_ai_key_valid,
display_file_read_error,
)

from knowledge_gpt.core.caching import bootstrap_caching
Expand Down Expand Up @@ -43,8 +44,11 @@
if not uploaded_file:
st.stop()

try:
file = read_file(uploaded_file)
except Exception as e:
display_file_read_error(e)

file = read_file(uploaded_file)
chunked_file = chunk_file(file, chunk_size=300, chunk_overlap=0)

if not is_file_valid(file):
Expand Down
12 changes: 8 additions & 4 deletions knowledge_gpt/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from knowledge_gpt.core.parsing import File
import openai
from streamlit.logger import get_logger
from typing import NoReturn

logger = get_logger(__name__)

Expand All @@ -26,15 +27,18 @@ def is_query_valid(query: str) -> bool:

def is_file_valid(file: File) -> bool:
if len(file.docs) == 0 or len(file.docs[0].page_content.strip()) == 0:
st.error(
"Cannot read document! Make sure the document has"
" selectable text or is not password protected."
)
st.error("Cannot read document! Make sure the document has selectable text")
logger.error("Cannot read document")
return False
return True


def display_file_read_error(e: Exception) -> NoReturn:
st.error("Error reading file. Make sure the file is not corrupted or encrypted")
logger.error(f"{e.__class__.__name__}: {e}")
st.stop()


@st.cache_data(show_spinner=False)
def is_open_ai_key_valid(openai_api_key) -> bool:
if not openai_api_key:
Expand Down
43 changes: 42 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pillow = "^9.4.0"
pypdf = "^3.3.0"
tenacity = "^8.2.0"
tiktoken = "^0.4.0"
pycryptodome = "^3.18.0"


[tool.poetry.group.dev.dependencies]
Expand Down

0 comments on commit 0a2868d

Please sign in to comment.