Spaces:
Running
Running
File size: 3,225 Bytes
fbdcaaf 9ff2b7e fd07ca2 fbdcaaf fd07ca2 5182c3f fbdcaaf fd07ca2 fbdcaaf fd07ca2 fbdcaaf fd07ca2 fbdcaaf b7ee1cf fd07ca2 b7ee1cf fd07ca2 fbdcaaf fd07ca2 fbdcaaf 6a8e235 fd07ca2 5ff038b fd07ca2 fbdcaaf 8bab72c fbdcaaf 5ff038b 6ff901a 5ff038b b7ee1cf 5ff038b b7ee1cf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# imports
import streamlit as st
import numpy as np
import pandas as pd
import re
import json
import openai
openai.api_key = st.secrets["open_ai_key"]
# state management
if 'gpt_response' not in st.session_state:
st.session_state.gpt_response = None
# app
user_direction = st.text_area(
"Let's get cooking! What do you feel like making?",
placeholder="quick snack, asian style bowl with either noodles or rice, something italian",
)
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."
])
exclusions = st.text_area(
"Any ingredients you want to exclude?",
placeholder="gluten, dairy, nuts, cilantro",
)
user_inputs = {
"user_direction" : user_direction,
"exclusions": exclusions,
"serving_size": serving_size,
"difficulty": difficulty
}
def generate_recipe(user_inputs):
context = """Provide me a recipe based on the user input.
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: "4 people")
recipe_time (string): the amount of time required to make the recipe (example: "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": str(user_inputs)}
]
st.session_state.gpt_response = openai.ChatCompletion.create(
model="gpt-4",
messages=messages,
temperature=0.5
)
st.button(label='Submit', on_click=generate_recipe, kwargs=dict(user_inputs=user_inputs))
if st.session_state.gpt_response is not None:
st.divider()
loaded_recipe = json.loads(st.session_state.gpt_response['choices'][0]['message']['content'])
st.header(loaded_recipe['recipe_name'])
st.text(f"**Serving Size: {loaded_recipe['recipe_serving_size']}**")
st.text(f"**Time To Make: {loaded_recipe['recipe_time']}**")
st.subheader("Ingredients:")
md_ingredients = ''
for ingredient in loaded_recipe['recipe_ingredients']:
md_ingredients += "- " + ingredient + "\n"
st.markdown(md_ingredients)
st.subheader("Instructions:")
md_instructions = ''
for instruction in loaded_recipe['recipe_instructions']:
md_instructions += "- " + instruction + "\n"
st.markdown(md_instructions) |