adrianpierce commited on
Commit
fbdcaaf
1 Parent(s): 5182c3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -12
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import streamlit as st
2
  import numpy as np
3
  import pandas as pd
@@ -6,9 +7,14 @@ import json
6
  import openai
7
  openai.api_key = st.secrets["open_ai_key"]
8
 
 
 
 
 
 
9
  user_direction = st.text_area(
10
  "Let's get cooking! What do you feel like making?",
11
- placeholder="quick snack, asian style bowl with either noodles or rice, something italian, ...",
12
  )
13
 
14
  serving_size = st.number_input(
@@ -28,16 +34,21 @@ difficulty = st.radio(
28
  "Complex recipes that demand a high level of skill and precision. Suited for seasoned cooks aspiring to professional-level sophistication and creativity."
29
  ])
30
 
 
 
 
 
 
31
  user_inputs = {
32
  "user_direction" : user_direction,
33
- "exclusions": "gluten, dairy",
34
- "serving_size": 4,
35
- "difficulty": "easy"
36
  }
37
 
38
- # define GPT agents
39
- def generate_recipe(text):
40
- context = """Provide me a recipe based on the below user input. The recipe output should contain the following components:
41
  - recipe name
42
  - serving size
43
  - time to make
@@ -52,14 +63,17 @@ def generate_recipe(text):
52
  """
53
  messages = [
54
  {"role": "system", "content": context},
55
- {"role": "user", "content": text}
56
  ]
57
- response = openai.ChatCompletion.create(
 
58
  model="gpt-3.5-turbo",
59
  messages=messages,
60
  temperature=0.2
61
  )
62
- response_message = response["choices"][0]["message"]
63
- return json.loads(response_message["content"])
64
 
65
- #generate_recipe(str(user_inputs))
 
 
 
 
 
1
+ # imports
2
  import streamlit as st
3
  import numpy as np
4
  import pandas as pd
 
7
  import openai
8
  openai.api_key = st.secrets["open_ai_key"]
9
 
10
+ # state management
11
+ if 'gpt_response' not in st.session_state:
12
+ st.session_state.gpt_response = None
13
+
14
+ # app
15
  user_direction = st.text_area(
16
  "Let's get cooking! What do you feel like making?",
17
+ placeholder="quick snack, asian style bowl with either noodles or rice, something italian",
18
  )
19
 
20
  serving_size = st.number_input(
 
34
  "Complex recipes that demand a high level of skill and precision. Suited for seasoned cooks aspiring to professional-level sophistication and creativity."
35
  ])
36
 
37
+ exclusions = st.text_area(
38
+ "Any ingredients you want to exclude?",
39
+ placeholder="gluten, dairy, nuts, cilantro",
40
+ )
41
+
42
  user_inputs = {
43
  "user_direction" : user_direction,
44
+ "exclusions": exclusions,
45
+ "serving_size": serving_size,
46
+ "difficulty": difficulty
47
  }
48
 
49
+
50
+ def generate_recipe(user_inputs):
51
+ context = """Provide me a recipe based on the user input. The recipe output should contain the following components:
52
  - recipe name
53
  - serving size
54
  - time to make
 
63
  """
64
  messages = [
65
  {"role": "system", "content": context},
66
+ {"role": "user", "content": str(user_inputs)}
67
  ]
68
+
69
+ st.session_state.gpt_response = openai.ChatCompletion.create(
70
  model="gpt-3.5-turbo",
71
  messages=messages,
72
  temperature=0.2
73
  )
 
 
74
 
75
+
76
+ st.button(label='Submit', on_click=get_response, kwargs=dict(user_inputs=user_inputs))
77
+
78
+ if st.session_state.gpt_response is not None:
79
+ st.json(json.loads(st.session_state.gpt_response['choices'][0]['message']['content']))