import numpy as np import pandas as pd import re import json import openai openai.api_key = st.secrets["open_ai_key"] user_direction = st.text_area( "Let's get cooking! What are you in the mood for?", value="quick snack, asian style bowl with either noodles or rice, chocolate indulgence, etc.", ) serving_size = st.number_input( "How many people are you cooking for?", min_value=1, max_value=100, value=2, step=1 ) difficulty = st.radio( "Choose a difficulty level for your recipe.", ["Beginner", "Home Chef", "Professional"], captions = [ "Easy recipes with straightforward instructions. Ideal for first-timers or those seeking quick and simple cooking.", "Recipes with some intricate steps that invite a little challenge. Perfect for regular cooks wanting to expand their repertoire with new ingredients and techniques.", "Complex recipes that demand a high level of skill and precision. Suited for seasoned cooks aspiring to professional-level sophistication and creativity." ]) user_inputs = { "user_direction" : user_direction, "exclusions": "gluten, dairy", "serving_size": 4, "difficulty": "easy" } # define GPT agents def generate_recipe(text): context = """Provide me a recipe based on the below user input. The recipe output should contain the following components: - recipe name - serving size - time to make - ingredients list - instructions Output this in a valid JSON object with the following properties: recipe_name (string): the name of the recipe recipe_serving_size (string): the serving size of the recipe (example: "Serving Size: 4 people") recipe_time (string): the amount of time required to make the recipe (example: "Time to Make: 60 minutes (Preparation: 20 minutes, Baking: 40 minutes)") recipe_ingredients (string): python list of ingredients required to make the recipe recipe_instructions (string): python list of instructions to make the recipe """ messages = [ {"role": "system", "content": context}, {"role": "user", "content": text} ] response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=messages, temperature=0.2 ) response_message = response["choices"][0]["message"] return json.loads(response_message["content"]) #generate_recipe(str(user_inputs))