Skip to content

Sec 4 - Final Project - AI Meal Planner on Cloud

Step-by-Step Guide to Building a Streamlit App for AI-Powered Meal Planning

Creating a user-friendly meal planning application powered by AI can enhance the cooking experience by providing tailored recipe suggestions based on available ingredients, dietary restrictions, and cooking preferences. This guide details the development of the "Detikfood Meal Prep Planner," a Streamlit web application integrated with OpenAI's GPT-3.5-turbo model.

Step 1: Set Up Your Development Environment

Install Necessary Libraries:
Install Streamlit and any necessary libraries by running:
pip install streamlit streamlit_tags openai
Import Libraries:
Start your Python script by importing the required modules:
import os
import streamlit as st from streamlit_tags
import st_tags
import openai

Step 2: Configure OpenAI API

API Key:
Set up your OpenAI API key. It is critical for authenticating your requests to the GPT-3.5-turbo API.
openai.api_key = "your_openai_api_key_here"

Step 3: Define the AI Interaction Function

Create the Function to Interact with GPT-3.5-turbo:
Define a function that constructs the prompt from user inputs and sends it to the AI model:
python
Copy code
def ask_gpt3_turbo(message): response = openai.chat.completions.create( model="gpt-3.5-turbo", messages=[ {"role": "system", "content": "You are an AI agent acting as a skilled chef who can create recipes from limited ingredients, specializing in Indonesian and regional cuisines."}, {"role": "user", "content": message}, ] ) return response['choices'][0]['message']['content']

Step 4: Build the Streamlit User Interface

Define the Main Function:
Code the main function where you'll design the user interface and handle interactions:
python
Copy code
def main(): st.title("Detikfood Meal Prep Planner")
User Input Fields:
Implement various input fields to collect user data:
bahan = st_tags(label="List the ingredients you have:") daerah = st.text_input("Are you looking for regional recipes? (e.g., Java, Sumatra, Bali)") # Add other inputs similarly
Recipe Request Button:
Add a button that users click to generate recipes based on their inputs:
if st.button("Generate Recipes"): ai_response = ask_gpt3_turbo(construct_prompt(...)) st.markdown(ai_response, unsafe_allow_html=True)

Step 5: Run and Test Your Application

Execute the App:
Save your script and run your Streamlit application by typing in your terminal:
streamlit run your_script_name.py
Interact and Debug:
Open the provided local URL in your web browser to view and interact with your application. Ensure all functionalities work as expected and make any necessary adjustments.

Step 6: Deployment

Deploy Your App:
Consider deploying your app on platforms like Heroku, AWS, or Google Cloud to make it accessible online. Follow the specific guidelines provided by these platforms for deploying Streamlit apps.
This guide outlines creating an interactive, AI-powered meal planning application using Streamlit and OpenAI's GPT-3.5-turbo. By following these steps, you can build a functional tool that offers customized cooking solutions, making meal preparation easier and more enjoyable.

Prompt

The prompt construction in the "Detikfood Meal Prep Planner" application plays a crucial role in defining the interaction between the user and the AI model, specifically OpenAI's GPT-3.5-turbo. The prompt essentially sets the stage for how the AI will understand and respond to the user's request for meal suggestions based on their inputs. Here's a step-by-step breakdown of how the prompt is structured and its function within the application:

Understanding the Prompt Structure

1. Prompt Definition

The prompt is a structured text input that is sent to the AI model. It includes instructions and criteria that guide the AI in generating content—in this case, meal recipes. This prompt is formulated based on user input, which includes ingredients, meal types, dietary preferences, and more.

2. User Inputs Considered in the Prompt

Ingredients: The user lists the ingredients they have available.
This link can't be embedded.
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.