First, we need to install the necessary libraries:
Now we can create .env file and add our OpenAI API key:
Last thing we need to do is to create main.py file, import all necessary libraries and load our API key from .env file:
Now we can create our Streamlit app. First, we need to create a functions that will generate prompt and trip schedule based on user input:
example_destinations = ['Paris', 'London', 'New York', 'Tokyo', 'Sydney', 'Hong Kong', 'Singapore', 'Warsaw', 'Mexico City', 'Palermo']
random_destination = random.choice(example_destinations)
now_date = datetime.now()
# round to nearest 15 minutes
now_date = now_date.replace(minute=now_date.minute // 15 * 15, second=0, microsecond=0)
# split into date and time objects
now_time = now_date.time()
now_date = now_date.date() + timedelta(days=1)
def generate_prompt(destination, arrival_to, arrival_date, arrival_time, departure_from, departure_date, departure_time, additional_information, **kwargs):
return f'''
Prepare trip schedule for {destination}, based on the following information:
* Arrival To: {arrival_to}
* Arrival Date: {arrival_date}
* Arrival Time: {arrival_time}
* Departure From: {departure_from}
* Departure Date: {departure_date}
* Departure Time: {departure_time}
* Additional Notes: {additional_information}
'''.strip()
def submit():
prompt = generate_prompt(**st.session_state)
# generate output
output = openai.Completion.create(
engine='text-davinci-003',
prompt=prompt,
temperature=0.45,
top_p=1,
frequency_penalty=2,
presence_penalty=0,
max_tokens=1024
)
st.session_state['output'] = output['choices'][0]['text']
Now we can create UI for our app with Streamlit:
Let's create form for user input:
And finally, we can display generated trip schedule:
Now we can run our app:
And let's check results!