OmPrakashSingh1704 commited on
Commit
f55ba65
1 Parent(s): 50f440d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -16
app.py CHANGED
@@ -54,16 +54,72 @@ def create_detailed_prompt(user_direction, exclusions, serving_size, difficulty)
54
  def generate_recipe(user_inputs):
55
  with st.spinner('Building the perfect recipe...'):
56
  prompt = create_detailed_prompt(user_inputs['user_direction'], user_inputs['exclusions'], user_inputs['serving_size'], user_inputs['difficulty'])
57
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  generate_kwargs = dict(
59
  temperature=0.9,
60
- max_new_tokens=10000,
61
  top_p=0.9,
62
- repetition_penalty=1.0,
63
- do_sample=True,
64
  )
65
 
66
- response = client.text_generation(prompt, **generate_kwargs)
67
  st.session_state.recipe = response
68
  st.session_state.recipe_saved = False
69
 
@@ -147,17 +203,17 @@ with button_cols_submit[2]:
147
  if st.session_state.recipe is not None:
148
  st.divider()
149
  print(st.session_state.recipe)
150
- # recipe = json.loads(st.session_state.recipe)
151
- # recipe_md = ''
152
- # recipe_md += f'# {recipe["name"]} \n\n'
153
- # recipe_md += f'{recipe["description"]} \n\n'
154
- # recipe_md += '## Ingredients: \n'
155
- # for ingredient in recipe['ingredients']:
156
- # recipe_md += f"- {ingredient['name']} \n"
157
- # recipe_md += '\n## Instructions:\n'
158
- # for instruction in recipe['instructions']:
159
- # recipe_md += f"{instruction['step_number']}. {instruction['instruction']} \n"
160
  # recipe['md'] = recipe_md
161
  # recipe['timestamp'] = str(datetime.now())
162
- st.markdown(st.session_state.recipe)
163
  st.write("")
 
54
  def generate_recipe(user_inputs):
55
  with st.spinner('Building the perfect recipe...'):
56
  prompt = create_detailed_prompt(user_inputs['user_direction'], user_inputs['exclusions'], user_inputs['serving_size'], user_inputs['difficulty'])
57
+ functions = [
58
+ {
59
+ "name": "provide_recipe",
60
+ "description": "Provides a detailed recipe strictly adhering to the user input/specifications, especially ingredient exclusions and the recipe difficulty",
61
+ "parameters": {
62
+ "type": "object",
63
+ "properties": {
64
+ "name": {
65
+ "type": "string",
66
+ "description": "A creative name for the recipe"
67
+ },
68
+ "description": {
69
+ "type": "string",
70
+ "description": "a brief one-sentence description of the provided recipe"
71
+ },
72
+ "ingredients": {
73
+ "type": "array",
74
+ "items": {
75
+ "type": "object",
76
+ "properties": {
77
+ "name": {
78
+ "type": "string",
79
+ "description": "Quantity and name of the ingredient"
80
+ }
81
+ }
82
+ }
83
+ },
84
+ "instructions": {
85
+ "type": "array",
86
+ "items": {
87
+ "type": "object",
88
+ "properties": {
89
+ "step_number": {
90
+ "type": "number",
91
+ "description": "The sequence number of this step"
92
+ },
93
+ "instruction": {
94
+ "type": "string",
95
+ "description": "Detailed description of what to do in this step"
96
+ }
97
+ }
98
+ }
99
+ }
100
+ },
101
+ "required": [
102
+ "name",
103
+ "description",
104
+ "ingredients",
105
+ "instructions"
106
+ ],
107
+ },
108
+ }
109
+ ]
110
+
111
+ prompt += f"\nPlease format the output in JSON. The JSON should include fields for 'name', 'description', 'ingredients', and 'instructions', with each field structured as described below.\n\n{functions}"
112
+
113
+
114
  generate_kwargs = dict(
115
  temperature=0.9,
116
+ max_tokens=10000,
117
  top_p=0.9,
118
+ frequency_penalty=1.0,
119
+ # do_sample=True,
120
  )
121
 
122
+ response = client.chat_completion(prompt, **generate_kwargs)
123
  st.session_state.recipe = response
124
  st.session_state.recipe_saved = False
125
 
 
203
  if st.session_state.recipe is not None:
204
  st.divider()
205
  print(st.session_state.recipe)
206
+ recipe = json.loads(st.session_state.recipe)
207
+ recipe_md = ''
208
+ recipe_md += f'# {recipe["name"]} \n\n'
209
+ recipe_md += f'{recipe["description"]} \n\n'
210
+ recipe_md += '## Ingredients: \n'
211
+ for ingredient in recipe['ingredients']:
212
+ recipe_md += f"- {ingredient['name']} \n"
213
+ recipe_md += '\n## Instructions:\n'
214
+ for instruction in recipe['instructions']:
215
+ recipe_md += f"{instruction['step_number']}. {instruction['instruction']} \n"
216
  # recipe['md'] = recipe_md
217
  # recipe['timestamp'] = str(datetime.now())
218
+ st.markdown(recipe_md)
219
  st.write("")