Spaces:
Sleeping
Sleeping
Commit
·
54d28e7
1
Parent(s):
2f571a9
Update app.py
Browse files
app.py
CHANGED
@@ -3,8 +3,11 @@ import numpy as np
|
|
3 |
import pandas as pd
|
4 |
import re
|
5 |
import json
|
6 |
-
import
|
7 |
-
|
|
|
|
|
|
|
8 |
|
9 |
# state management
|
10 |
if 'gpt_response' not in st.session_state:
|
@@ -95,8 +98,8 @@ def generate_recipe(user_inputs):
|
|
95 |
]
|
96 |
prompt = create_detailed_prompt(user_inputs['user_direction'], user_inputs['exclusions'], user_inputs['serving_size'], user_inputs['difficulty'])
|
97 |
messages = [{"role": "user", "content": prompt}]
|
98 |
-
st.session_state.gpt_response =
|
99 |
-
model="gpt-4",
|
100 |
messages=messages,
|
101 |
temperature=0.75,
|
102 |
top_p=0.75,
|
@@ -175,24 +178,15 @@ st.button(label='Submit', on_click=generate_recipe, kwargs=dict(user_inputs=user
|
|
175 |
|
176 |
if st.session_state.gpt_response is not None:
|
177 |
st.divider()
|
178 |
-
loaded_recipe = json.loads(st.session_state.gpt_response
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
st.write(loaded_recipe['ingredients'])
|
190 |
-
st.subheader("Instructions:")
|
191 |
-
try:
|
192 |
-
md_instructions = ''
|
193 |
-
for instruction in loaded_recipe['instructions']:
|
194 |
-
md_instructions += f"{instruction['step_number']}. {instruction['instruction']} \n"
|
195 |
-
st.markdown(md_instructions)
|
196 |
-
except:
|
197 |
-
st.write(loaded_recipe['instructions'])
|
198 |
# st.button("📋", on_click=on_copy_click, args=(full_response,))
|
|
|
3 |
import pandas as pd
|
4 |
import re
|
5 |
import json
|
6 |
+
from openai import OpenAI
|
7 |
+
|
8 |
+
client = OpenAI(
|
9 |
+
api_key = st.secrets["open_ai_key"]
|
10 |
+
)
|
11 |
|
12 |
# state management
|
13 |
if 'gpt_response' not in st.session_state:
|
|
|
98 |
]
|
99 |
prompt = create_detailed_prompt(user_inputs['user_direction'], user_inputs['exclusions'], user_inputs['serving_size'], user_inputs['difficulty'])
|
100 |
messages = [{"role": "user", "content": prompt}]
|
101 |
+
st.session_state.gpt_response = client.chat.completions.create(
|
102 |
+
model="gpt-4-1106-preview",
|
103 |
messages=messages,
|
104 |
temperature=0.75,
|
105 |
top_p=0.75,
|
|
|
178 |
|
179 |
if st.session_state.gpt_response is not None:
|
180 |
st.divider()
|
181 |
+
loaded_recipe = json.loads(st.session_state.gpt_response.choices[0].message.function_call.arguments)
|
182 |
+
recipe_md = ''
|
183 |
+
recipe_md += f'#{recipe["name"]} \n\n'
|
184 |
+
recipe_md += f'{recipe["description"]} \n\n'
|
185 |
+
recipe_md += f'##Ingredients: \n'
|
186 |
+
for ingredient in recipe['ingredients']:
|
187 |
+
recipe_md += f"- {ingredient['name']} \n"
|
188 |
+
recipe_md += f'\n##Instructions:\n'
|
189 |
+
for instruction in recipe['instructions']:
|
190 |
+
recipe_md += f"{instruction['step_number']}. {instruction['instruction']} \n"
|
191 |
+
st.markdown(recipe_md)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
# st.button("📋", on_click=on_copy_click, args=(full_response,))
|