File size: 2,553 Bytes
410bfe2
756eb79
410bfe2
756eb79
 
c9f69da
ac2f32c
756eb79
 
 
 
 
 
915b176
bd8d864
49af185
756eb79
 
 
 
 
 
 
 
 
 
 
 
 
410bfe2
 
 
 
 
 
915b176
410bfe2
bd8d864
 
9a900bf
c9f69da
 
 
49af185
c9f69da
915b176
4474ada
c9f69da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4474ada
c9f69da
 
 
 
73c1f71
c9f69da
 
 
 
bd8d864
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import openai
import streamlit as st
from openai import OpenAI

# Initialize OpenAI
openai.api_key = os.environ['OPENAI_API_KEY']

client = OpenAI(
    api_key=os.environ['OPENAI_API_KEY']
)

# Function to generate the recipe and detailed instructions
def create_dish_prompt(list_of_ingredients, category):
    prompt = f"Make a {category} dish with the following ingredients: " + ', '.join(
        list_of_ingredients) + ".\nWrite down the title, detailed recipe, and a description of the image you want to generate.\n"
    return prompt

# Function to generate the image
def generate_dalle_image(recipe_title):
    response = client.images.generate(
        model="dall-e-3",
        prompt=recipe_title,
        size="1024x1024",
        quality="standard",
        n=1,
    )
    url = response.data[0].url if response.data else None
    return url

# Initialize Streamlit
st.image("logo 3.jpg")
st.title("AutoChef.AI")

# Create a text input box for users to input ingredients
list_of_ingredients = st.text_input("Enter your ingredients (comma-separated):", "")

# Create a text input for users to input the category of food
category = st.text_input("Enter the category of food such as fried, baked, grilled, etc:")

# Generate Recipe button at the bottom
if st.button("Generate Recipe"):
    # Check if the user has entered ingredients
    if list_of_ingredients:
        # Convert the input string into a list of ingredients
        list_of_ingredients = [item.strip() for item in list_of_ingredients.split(',')]

        # Call your existing functions to generate the recipe and image
        recipe = create_dish_prompt(list_of_ingredients, category)
        completion = client.chat.completions.create(
            messages=[
                {
                    "role": "user",
                    "content": recipe,
                }
            ],
            model="gpt-3.5-turbo",
        )
        content = completion.choices[0].message.content
        split_content = content.split('\n', 1)
        recipe_title = split_content[0].strip()
        detailed_recipe = split_content[1].strip()
        url = generate_dalle_image(recipe_title)

        # Display the recipe title and detailed recipe
        st.title(recipe_title)
        st.subheader("A comprehensive culinary guide outlining the step-by-step procedure for preparing a dish.")
        st.write(detailed_recipe)

        # Display the image if a URL exists
        if url:
            st.image(url)
        else:
            st.write("No image URL generated.")