Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
snova-jorgep committed Jan 7, 2025
1 parent 50af0a7 commit 359feeb
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions enterprise_knowledge_retriever/streamlit/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def load_app_description() -> Any:
with open(APP_DESCRIPTION_PATH, 'r') as yaml_file:
return yaml.safe_load(yaml_file)


def delete_temp_dir(temp_dir: str) -> None:
"""Delete the temporary directory and its contents."""

Expand All @@ -52,7 +53,8 @@ def delete_temp_dir(temp_dir: str) -> None:
logging.info(f'Temporary directory {temp_dir} deleted.')
except:
logging.info(f'Could not delete temporary directory {temp_dir}.')



def schedule_temp_dir_deletion(temp_dir: str, delay_minutes: int) -> None:
"""Schedule the deletion of the temporary directory after a delay."""

Expand All @@ -66,6 +68,7 @@ def run_scheduler() -> None:
# Run scheduler in a separate thread to be non-blocking
Thread(target=run_scheduler, daemon=True).start()


def save_files_user(docs: List[UploadedFile], schedule_deletion: bool = True) -> str:
"""
Save all user uploaded files in Streamlit to the tmp dir with their file names
Expand Down Expand Up @@ -102,13 +105,13 @@ def save_files_user(docs: List[UploadedFile], schedule_deletion: bool = True) ->
temp_file = os.path.join(temp_folder, doc.name)
with open(temp_file, 'wb') as f:
f.write(doc.getvalue())

if schedule_deletion:
schedule_temp_dir_deletion(temp_folder, EXIT_TIME_DELTA)
st.toast(
"""your session will be active for the next 30 minutes, after this time files
will be deleted"""
)
)

return temp_folder

Expand Down Expand Up @@ -307,7 +310,7 @@ def main() -> None:
)
embeddings = st.session_state.document_retrieval.load_embedding_model()
collection_name = default_collection if not prod_mode else None
save_location = temp_folder+'_db'
save_location = temp_folder + '_db'
if prod_mode:
schedule_temp_dir_deletion(save_location, EXIT_TIME_DELTA)
vectorstore = st.session_state.document_retrieval.create_vector_store(
Expand Down

0 comments on commit 359feeb

Please sign in to comment.