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
…88)

* feat: Add description to the parenting chatbot and create public app

* chore: Change title and text

* feat: Create new streamlit apps
  • Loading branch information
kstathou authored Sep 27, 2023
1 parent 6756ac8 commit d0d4cef
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 23 deletions.
30 changes: 30 additions & 0 deletions public_activity_recommender_app.py
Original file line number Diff line number Diff line change
@@ -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()
30 changes: 30 additions & 0 deletions public_eli3_app.py
Original file line number Diff line number Diff line change
@@ -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()
45 changes: 45 additions & 0 deletions public_parenting_chatbot_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()
11 changes: 8 additions & 3 deletions src/genai/streamlit_pages/dm_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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**",
Expand Down
36 changes: 20 additions & 16 deletions src/genai/streamlit_pages/eli3_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
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("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")
Expand Down

0 comments on commit d0d4cef

Please sign in to comment.