diff --git a/public_app.py b/public_app.py new file mode 100644 index 0000000..bcabdb0 --- /dev/null +++ b/public_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/parenting_page.py b/src/genai/streamlit_pages/parenting_page.py index 8df160c..60dc998 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("NHS Start for Life chatbot") + st.write( + "This is a chatbot for 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")