Skip to content

Commit

Permalink
feat: Add description to the parenting chatbot and create public app
Browse files Browse the repository at this point in the history
  • Loading branch information
kstathou committed Sep 25, 2023
1 parent 260311f commit 106ee29
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
45 changes: 45 additions & 0 deletions public_app.py
Original file line number Diff line number Diff line change
@@ -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()
15 changes: 11 additions & 4 deletions src/genai/streamlit_pages/parenting_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 106ee29

Please sign in to comment.