diff --git a/public_activity_recommender_app.py b/public_activity_recommender_app.py new file mode 100644 index 0000000..be5b925 --- /dev/null +++ b/public_activity_recommender_app.py @@ -0,0 +1,30 @@ +"""Streamlit app for the Generative AI prototypes.""" + +import os + +import openai +import streamlit as st + +from dotenv import load_dotenv + +from genai.streamlit_pages import eyfs_dm_kb + + +load_dotenv() + + +def auth_openai() -> None: + """Authenticate with OpenAI.""" + try: + openai.api_key = os.environ["OPENAI_API_KEY"] + except Exception: + openai.api_key = st.secrets["OPENAI_API_KEY"] + + +def main() -> None: + """Run the app.""" + auth_openai() + eyfs_dm_kb(sidebar=False) + + +main() diff --git a/public_eli3_app.py b/public_eli3_app.py new file mode 100644 index 0000000..926eb79 --- /dev/null +++ b/public_eli3_app.py @@ -0,0 +1,30 @@ +"""Streamlit app for the Generative AI prototypes.""" + +import os + +import openai +import streamlit as st + +from dotenv import load_dotenv + +from genai.streamlit_pages import eli3 + + +load_dotenv() + + +def auth_openai() -> None: + """Authenticate with OpenAI.""" + try: + openai.api_key = os.environ["OPENAI_API_KEY"] + except Exception: + openai.api_key = st.secrets["OPENAI_API_KEY"] + + +def main() -> None: + """Run the app.""" + auth_openai() + eli3(sidebar=False) + + +main() diff --git a/public_parenting_chatbot_app.py b/public_parenting_chatbot_app.py new file mode 100644 index 0000000..bcabdb0 --- /dev/null +++ b/public_parenting_chatbot_app.py @@ -0,0 +1,45 @@ +"""Streamlit app for the Generative AI prototypes.""" + +import os + +import openai +import streamlit as st + +from dotenv import load_dotenv + +from genai.streamlit_pages import parenting_chatbot + + +load_dotenv() + + +def auth_openai() -> None: + """Authenticate with OpenAI.""" + try: + openai.api_key = os.environ["OPENAI_API_KEY"] + except Exception: + openai.api_key = st.secrets["OPENAI_API_KEY"] + + +def s3_creds() -> None: + """Get s3 creds.""" + try: + aws_key = os.environ["AWS_ACCESS_KEY_ID"] + aws_secret = os.environ["AWS_SECRET_ACCESS_KEY"] + s3_path = os.environ["S3_BUCKET"] + except Exception: + aws_key = st.secrets["AWS_ACCESS_KEY_ID"] + aws_secret = st.secrets["AWS_SECRET_ACCESS_KEY"] + s3_path = st.secrets["S3_BUCKET"] + + return aws_key, aws_secret, s3_path + + +def main() -> None: + """Run the app.""" + auth_openai() + aws_key, aws_secret, s3_path = s3_creds() + parenting_chatbot(aws_key, aws_secret, s3_path, sidebar=False) + + +main() diff --git a/src/genai/streamlit_pages/dm_page.py b/src/genai/streamlit_pages/dm_page.py index befa684..888be13 100644 --- a/src/genai/streamlit_pages/dm_page.py +++ b/src/genai/streamlit_pages/dm_page.py @@ -12,7 +12,7 @@ from genai.utils import read_json -def eyfs_dm_kb(index_name: str = "eyfs-index") -> None: +def eyfs_dm_kb(index_name: str = "eyfs-index", sidebar: bool = True) -> None: """Run the Development Matters app.""" st.title("Generate activities anchored to the Development Matters guidance") areas_of_learning_desc = read_json("src/genai/eyfs/areas_of_learning.json") @@ -30,8 +30,13 @@ def eyfs_dm_kb(index_name: str = "eyfs-index") -> None: message = MessageTemplate.load("src/genai/dm/prompts/dm_prompt_2.json") - with st.sidebar: - selected_model, temperature, n_examples = sidebar() + if sidebar: + with st.sidebar: + selected_model, temperature, n_examples = sidebar() + else: + selected_model = "gpt-4" + temperature = 0.6 + n_examples = 5 choice = st.radio( label="**Select a learning goal**", diff --git a/src/genai/streamlit_pages/eli3_page.py b/src/genai/streamlit_pages/eli3_page.py index c3f00bb..cdf2f8c 100644 --- a/src/genai/streamlit_pages/eli3_page.py +++ b/src/genai/streamlit_pages/eli3_page.py @@ -5,27 +5,31 @@ from genai.streamlit_pages.utils import reset_state -def eli3() -> None: +def eli3(sidebar: bool = True) -> None: """Explain me a concept like I'm 3.""" st.title("Explain like I am a three year old") # Create the generator - with st.sidebar: - selected_model = st.radio( - label="**OpenAI model**", - options=["gpt-3.5-turbo", "gpt-4"], - on_change=reset_state, - ) - temperature = st.slider( - label="**Temperature**", - min_value=0.0, - max_value=2.0, - value=0.6, - step=0.1, - on_change=reset_state, - ) + if sidebar: + with st.sidebar: + selected_model = st.radio( + label="**OpenAI model**", + options=["gpt-3.5-turbo", "gpt-4"], + on_change=reset_state, + ) + temperature = st.slider( + label="**Temperature**", + min_value=0.0, + max_value=2.0, + value=0.6, + step=0.1, + on_change=reset_state, + ) - st.button("Reset chat", on_click=reset_state, type="primary", help="Reset the chat history") + st.button("Reset chat", on_click=reset_state, type="primary", help="Reset the chat history") + else: + selected_model = "gpt-4" + temperature = 0.6 prompt_template = MessageTemplate.load("src/genai/eli3/prompts/eli3_chat_2.json") diff --git a/src/genai/streamlit_pages/parenting_page.py b/src/genai/streamlit_pages/parenting_page.py index 8df160c..f8a3512 100644 --- a/src/genai/streamlit_pages/parenting_page.py +++ b/src/genai/streamlit_pages/parenting_page.py @@ -22,16 +22,23 @@ load_dotenv() -def parenting_chatbot(aws_key: str, aws_secret: str, s3_path: str) -> None: +def parenting_chatbot(aws_key: str, aws_secret: str, s3_path: str, sidebar: bool = True) -> None: """Parenting chatbot.""" - st.title("Parenting Chatbot") + st.title("Parenting chatbot") + st.write( + "This is a chatbot based on the [NHS Start for Life](https://www.nhs.uk/start-for-life/) website. " + "You can ask it questions about pregnancy, birth and parenthood. " + "Please note that this is a prototype and the answers are not intended to be used as medical advice." + ) + st.write("---") selected_model = "gpt-3.5-turbo" temperature = 0.6 pinecone_index = get_index(index_name="eyfs-index") - with st.sidebar: - st.button("Reset chat", on_click=reset_state, type="primary", help="Reset the chat history") + if sidebar: + with st.sidebar: + st.button("Reset chat", on_click=reset_state, type="primary", help="Reset the chat history") system_message = MessageTemplate.load("src/genai/parenting_chatbot/prompts/system.json") filter_refs_function = FunctionTemplate.load("src/genai/parenting_chatbot/prompts/filter_refs_function.json")