In the rapidly evolving landscape of AI-driven applications, providing personalized and empathetic support is becoming increasingly attainable. Our latest project exemplifies this by delivering a unique Parenting Assistant built using the Lyzr SDK and OpenAI’s powerful language models. This blog post will walk you through the development and deployment of a Streamlit app designed to offer personalized parenting advice.
Parenting can be challenging, and having access to expert advice can make a significant difference. Our Parenting Assistant app harnesses the power of AI to provide tailored guidance to parents on various topics, including feeding, sleep, development, behavior, health, and safety.
Why use Lyzr SDK’s?
With Lyzr SDKs, crafting your own GenAI application is a breeze, requiring only a few lines of code to get up and running swiftly.
Lets get Started!
Create an app.py file
First, we need to import the necessary libraries and set up the OpenAI API key using Streamlit’s secret management feature.
import streamlit as st
from lyzr_automata.ai_models.openai import OpenAIModel
from lyzr_automata import Agent, Task
from lyzr_automata.pipelines.linear_sync_pipeline import LinearSyncPipeline
from PIL import Image
from lyzr_automata.tasks.task_literals import InputType, OutputType
import os
# Set the OpenAI API key
os.environ["OPENAI_API_KEY"] = st.secrets["apikey"]
Customizing the App Appearance
We use custom CSS to hide the default Streamlit header and adjust the padding for a cleaner look.
st.markdown(
"""
<style>
.app-header { visibility: hidden; }
.css-18e3th9 { padding-top: 0; padding-bottom: 0; }
.css-1d391kg { padding-top: 1rem; padding-right: 1rem; padding-bottom: 1rem; padding-left: 1rem; }
</style>
""",
unsafe_allow_html=True,
)
User Input
We create a text input field for parents to enter their questions or concerns.
input = st.text_input("Please enter your questions or concerns", placeholder="Type here")
Configuring the AI Model
We define the OpenAI model parameters, including the API key, model type, temperature, and max tokens.
open_ai_text_completion_model = OpenAIModel(
api_key=st.secrets["apikey"],
parameters={
"model": "gpt-4-turbo-preview",
"temperature": 0.2,
"max_tokens": 1500,
},
)
Generating Responses
We define the function to generate responses using the Lyzr SDK. This function sets up the agent and task to process the input and provide tailored advice.
def generation(input):
generator_agent = Agent(
role=" Expert PARENTING ASSISTANT",
prompt_persona=f"Your task is to PROVIDE GUIDANCE and PERSONALIZED ADVICE to parents seeking help on a wide range of parenting topics and specific situations they may encounter with their children.")
prompt = f"""
[prompts here]
"""
"""
generator_agent_task = Task(
name="Generation",
model=open_ai_text_completion_model,
agent=generator_agent,
instructions=prompt,
default_input=input,
output_type=OutputType.TEXT,
input_type=InputType.TEXT,
).execute()
return generator_agent_task
Displaying the Response
We set up a button to trigger the response generation and display the result using Streamlit.
if st.button("Advise"):
solution = generation(input)
st.markdown(solution)
About Section
We add an expandable section with additional information about the app and links to the Lyzr website and support channels.
with st.expander("ℹ️ - About this App"):
st.markdown("""
This app uses Lyzr Automata Agent . For any inquiries or issues, please contact Lyzr.
""")
st.link_button("Lyzr", url='https://www.lyzr.ai/', use_container_width=True)
st.link_button("Book a Demo", url='https://www.lyzr.ai/book-demo/', use_container_width=True)
st.link_button("Discord", url='https://discord.gg/nm7zSyEFA2', use_container_width=True)
st.link_button("Slack",
url='https://join.slack.com/t/genaiforenterprise/shared_invite/zt-2a7fr38f7-_QDOY1W1WSlSiYNAEncLGw',
use_container_width=True)
The Parenting Assistant app demonstrates how advanced AI models can be leveraged to provide personalized support and foster a community among parents. By integrating Streamlit with the Lyzr SDK and OpenAI’s language models, we have created a powerful tool that can assist parents in navigating the complexities of raising children.
We hope this guide inspires you to build your own AI-driven applications and explore the potential of integrating advanced AI capabilities into user-friendly interfaces.
App link: https://github.com/isakshay007/Parenting_App
Source Code: https://parentingapp-lyzr.streamlit.app/
Connect with Lyzr
To learn more about Lyzr and its SDK’s, visit our website or get in touch with our team:
Website: Lyzr.ai
Book a Demo: Book a Demo
Discord: Join our Discord community
Slack: Join our Slack channel
Top comments (0)