feat: improve performance by implementing lazy loading, caching, and efficient file handling in alwrity.py and alwrity_utils.py
This commit is contained in:
@@ -2,11 +2,12 @@ import os
|
|||||||
import json
|
import json
|
||||||
import base64
|
import base64
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from dotenv import load_dotenv
|
|
||||||
import streamlit as st
|
import streamlit as st
|
||||||
|
|
||||||
# Load .env file
|
# Load .env file
|
||||||
load_dotenv()
|
def load_environment():
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
from lib.utils.alwrity_utils import (
|
from lib.utils.alwrity_utils import (
|
||||||
blog_from_keyword, ai_agents_team, essay_writer, ai_news_writer, ai_seo_tools,
|
blog_from_keyword, ai_agents_team, essay_writer, ai_news_writer, ai_seo_tools,
|
||||||
@@ -26,6 +27,7 @@ def process_folder_for_rag(folder_path):
|
|||||||
st.write(f"This is a placeholder for processing the folder: {folder_path}")
|
st.write(f"This is a placeholder for processing the folder: {folder_path}")
|
||||||
|
|
||||||
|
|
||||||
|
@st.cache_data
|
||||||
def check_api_keys():
|
def check_api_keys():
|
||||||
"""
|
"""
|
||||||
Checks if the required API keys are present in the environment variables.
|
Checks if the required API keys are present in the environment variables.
|
||||||
@@ -59,6 +61,7 @@ def check_api_keys():
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@st.cache_data
|
||||||
def check_llm_environs():
|
def check_llm_environs():
|
||||||
"""
|
"""
|
||||||
Ensures that the LLM provider and corresponding API key are set.
|
Ensures that the LLM provider and corresponding API key are set.
|
||||||
@@ -282,6 +285,7 @@ def sidebar_configuration():
|
|||||||
|
|
||||||
|
|
||||||
# Function to read prompts from the file
|
# Function to read prompts from the file
|
||||||
|
@st.cache_data
|
||||||
def read_prompts(file_path="prompt_llm.txt"):
|
def read_prompts(file_path="prompt_llm.txt"):
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
with open(file_path, "r") as file:
|
with open(file_path, "r") as file:
|
||||||
@@ -303,6 +307,7 @@ def load_image(image_path):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
load_environment()
|
||||||
setup_ui()
|
setup_ui()
|
||||||
setup_environment_paths()
|
setup_environment_paths()
|
||||||
sidebar_configuration()
|
sidebar_configuration()
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ from lib.content_planning_calender.content_planning_agents_alwrity_crew import a
|
|||||||
from ..gpt_providers.text_generation.main_text_generation import llm_text_gen
|
from ..gpt_providers.text_generation.main_text_generation import llm_text_gen
|
||||||
|
|
||||||
|
|
||||||
|
@st.cache_data
|
||||||
def record_voice(language="en"):
|
def record_voice(language="en"):
|
||||||
# https://github.com/B4PT0R/streamlit-mic-recorder?tab=readme-ov-file#example
|
# https://github.com/B4PT0R/streamlit-mic-recorder?tab=readme-ov-file#example
|
||||||
state = st.session_state
|
state = st.session_state
|
||||||
|
|||||||
Reference in New Issue
Block a user