Spaces:
Sleeping
Sleeping
Commit
·
fd07ca2
1
Parent(s):
146141c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import pandas as pd
|
3 |
+
import re
|
4 |
+
import json
|
5 |
+
import openai
|
6 |
+
openai.api_key = st.secrets["open_ai_key"]
|
7 |
+
|
8 |
+
user_direction = st.text_area(
|
9 |
+
"Let's get cooking! What are you in the mood for?",
|
10 |
+
value="quick snack, asian style bowl with either noodles or rice, chocolate indulgence, etc.",
|
11 |
+
)
|
12 |
+
|
13 |
+
serving_size = st.number_input(
|
14 |
+
"How many people are you cooking for?",
|
15 |
+
min_value=1,
|
16 |
+
max_value=100,
|
17 |
+
value=2,
|
18 |
+
step=1
|
19 |
+
)
|
20 |
+
|
21 |
+
difficulty = st.radio(
|
22 |
+
"Choose a difficulty level for your recipe.",
|
23 |
+
["Beginner", "Home Chef", "Professional"],
|
24 |
+
captions = [
|
25 |
+
"Easy recipes with straightforward instructions. Ideal for first-timers or those seeking quick and simple cooking.",
|
26 |
+
"Recipes with some intricate steps that invite a little challenge. Perfect for regular cooks wanting to expand their repertoire with new ingredients and techniques.",
|
27 |
+
"Complex recipes that demand a high level of skill and precision. Suited for seasoned cooks aspiring to professional-level sophistication and creativity."
|
28 |
+
])
|
29 |
+
|
30 |
+
user_inputs = {
|
31 |
+
"user_direction" : user_direction,
|
32 |
+
"exclusions": "gluten, dairy",
|
33 |
+
"serving_size": 4,
|
34 |
+
"difficulty": "easy"
|
35 |
+
}
|
36 |
+
|
37 |
+
# define GPT agents
|
38 |
+
def generate_recipe(text):
|
39 |
+
context = """Provide me a recipe based on the below user input. The recipe output should contain the following components:
|
40 |
+
- recipe name
|
41 |
+
- serving size
|
42 |
+
- time to make
|
43 |
+
- ingredients list
|
44 |
+
- instructions
|
45 |
+
Output this in a valid JSON object with the following properties:
|
46 |
+
recipe_name (string): the name of the recipe
|
47 |
+
recipe_serving_size (string): the serving size of the recipe (example: "Serving Size: 4 people")
|
48 |
+
recipe_time (string): the amount of time required to make the recipe (example: "Time to Make: 60 minutes (Preparation: 20 minutes, Baking: 40 minutes)")
|
49 |
+
recipe_ingredients (string): python list of ingredients required to make the recipe
|
50 |
+
recipe_instructions (string): python list of instructions to make the recipe
|
51 |
+
"""
|
52 |
+
messages = [
|
53 |
+
{"role": "system", "content": context},
|
54 |
+
{"role": "user", "content": text}
|
55 |
+
]
|
56 |
+
response = openai.ChatCompletion.create(
|
57 |
+
model="gpt-3.5-turbo",
|
58 |
+
messages=messages,
|
59 |
+
temperature=0.2
|
60 |
+
)
|
61 |
+
response_message = response["choices"][0]["message"]
|
62 |
+
return json.loads(response_message["content"])
|
63 |
+
|
64 |
+
#generate_recipe(str(user_inputs))
|