In this blog post, we’ll explore how to build a Travel Checklist Generator using Streamlit, the Lyzr Automata SDK, and OpenAI’s GPT-4 Turbo. This application will provide users with a customized packing list based on their travel details.
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!
First, we’ll set up the necessary imports and configure the OpenAI API key.
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"]
Here, we import the required libraries. streamlit is used to build the web application interface, while **lyzr_automata **provides the tools to create tasks and agents that interact with the OpenAI models. We also use PIL to handle images.
We then display the application’s title and introduction.
# App title and introduction
st.title("Travel Checklist Generator")
st.markdown("Welcome to Travel Checklist Generator, your personalized travel packing assistant! Simply input your destination and trip duration, and get a customized packing list tailored to your needs.")
st.markdown("1) Name of your travel destination.")
st.markdown("2) Mention the trip duration.")
st.markdown("3) Provide additional information if any like planned activities, accommodation type and others.")
This section loads and displays the Lyzr app’s title, and provides instructions for the user.
We create a text input field for users to enter their travel details.
input = st.text_input(" Please enter the above details:", placeholder=f"""Type here""")
Next, we set up the OpenAI model with specific parameters.
open_ai_text_completion_model = OpenAIModel(
api_key=st.secrets["apikey"],
parameters={
"model": "gpt-4-turbo-preview",
"temperature": 0.2,
"max_tokens": 1500,
},
)
We
use the GPT-4 Turbo model with a low temperature setting for more focused outputs and set a maximum token limit.
Generating the Travel Checklist
We define a function to generate the travel checklist based on user input.
def generation(input):
generator_agent = Agent(
role=" Expert TRAVEL PLANNER ",
prompt_persona=f"Your task is to DEVELOP a COMPREHENSIVE and CUSTOMIZED travel checklist for a user, based on the SPECIFIC INFORMATION they provide about their destination, trip duration, activities they plan to engage in, accommodation type, and any other relevant details.")
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
In this function, we create an Agent with a specific role and prompt persona. The prompt guides the agent to generate a comprehensive and customized travel checklist. We then define a Task to execute the agent's task with the provided input.
We add a button to trigger the checklist generation when clicked.
if st.button("Generate"):
solution = generation(input)
st.markdown(solution)
When the user clicks the “Generate” button, the generation function is called, and the output is displayed using st.markdown.
In this blog post, we’ve built a simple yet powerful Travel Checklist Generator using Streamlit, Lyzr Automata SDK, and OpenAI’s GPT-4 Turbo. This application provides a customized packing list based on user inputs, making travel planning more efficient and enjoyable. Feel free to extend this example further to suit more complex use cases and improve the user experience!
App link: https://travelchecklist-lyzr.streamlit.app/
Source Code: https://github.com/isakshay007/Travel_Checklist
The Travel Checklist Generator is powered by the Lyzr Automata Agent, utilizing the capabilities of OpenAI’s GPT-4 Turbo. For any inquiries or issues, please contact Lyzr. You can learn more about Lyzr and their offerings through the following links:
Website: Lyzr.ai
Book a Demo: Book a Demo
Discord: Join our Discord community
Slack: Join our Slack channel
Top comments (0)