Hussnainkha commited on
Commit
c9f69da
·
verified ·
1 Parent(s): 65244d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -38
app.py CHANGED
@@ -1,13 +1,10 @@
1
  import os
2
- import openai
3
  import streamlit as st
4
  from openai import OpenAI
5
 
 
6
  openai.api_key = os.environ['OPENAI_API_KEY']
7
-
8
- client = OpenAI(
9
- api_key=os.environ['OPENAI_API_KEY']
10
- )
11
 
12
  # Function to generate the recipe and detailed instructions
13
  def create_dish_prompt(ingredients, category):
@@ -37,39 +34,37 @@ ingredients = st.text_input("Enter your ingredients (comma-separated):", "")
37
  # Create a dropdown for users to select the category of food
38
  category = st.text_input("Enter the category of food such as fried, baked, grilled etc")
39
 
40
- # Check if the user has entered ingredients
41
- if ingredients:
42
- # Convert the input string into a list of ingredients
43
- list_of_ingredients = [item.strip() for item in ingredients.split(',')]
44
-
45
- # Call your existing functions to generate the recipe and image
46
- recipe = create_dish_prompt(list_of_ingredients, category)
47
- completion = client.chat.completions.create(
48
- messages=[
49
- {
50
- "role": "user",
51
- "content": recipe,
52
- }
53
- ],
54
- model="gpt-3.5-turbo",
55
- )
56
- content = completion.choices[0].message.content
57
- split_content = content.split('\n', 1)
58
- recipe_title = split_content[0].strip()
59
- detailed_recipe = split_content[1].strip()
60
- url = generate_dalle_image(recipe_title)
61
 
62
- # Display the recipe title and detailed recipe
63
- st.title(recipe_title)
64
- st.subheader("A comprehensive culinary guide outlining the step-by-step procedure for preparing a dish.")
65
- st.write(detailed_recipe)
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
- # Display the image if a URL exists
68
- if url:
69
- st.image(url)
70
- else:
71
- st.write("No image URL generated.")
72
 
73
- # Generate Recipe button at the bottom
74
- if st.button("Generate Recipe"):
75
- pass
 
 
 
1
  import os
 
2
  import streamlit as st
3
  from openai import OpenAI
4
 
5
+ # Initialize OpenAI
6
  openai.api_key = os.environ['OPENAI_API_KEY']
7
+ client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
 
 
 
8
 
9
  # Function to generate the recipe and detailed instructions
10
  def create_dish_prompt(ingredients, category):
 
34
  # Create a dropdown for users to select the category of food
35
  category = st.text_input("Enter the category of food such as fried, baked, grilled etc")
36
 
37
+ # Generate Recipe button at the bottom
38
+ if st.button("Generate Recipe"):
39
+ # Check if the user has entered ingredients
40
+ if ingredients:
41
+ # Convert the input string into a list of ingredients
42
+ list_of_ingredients = [item.strip() for item in ingredients.split(',')]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
+ # Call your existing functions to generate the recipe and image
45
+ recipe = create_dish_prompt(list_of_ingredients, category)
46
+ completion = client.chat.completions.create(
47
+ messages=[
48
+ {
49
+ "role": "user",
50
+ "content": recipe,
51
+ }
52
+ ],
53
+ model="gpt-3.5-turbo",
54
+ )
55
+ content = completion.choices[0].message.content
56
+ split_content = content.split('\n', 1)
57
+ recipe_title = split_content[0].strip()
58
+ detailed_recipe = split_content[1].strip()
59
+ url = generate_dalle_image(recipe_title)
60
 
61
+ # Display the recipe title and detailed recipe
62
+ st.title(recipe_title)
63
+ st.subheader("A comprehensive culinary guide outlining the step-by-step procedure for preparing a dish.")
64
+ st.write(detailed_recipe)
 
65
 
66
+ # Display the image if a URL exists
67
+ if url:
68
+ st.image(url)
69
+ else:
70
+ st.write("No image URL generated.")