| | |
| | import os |
| | import streamlit as st |
| | from groq import Groq |
| |
|
| | |
| | GROQ_API_KEY = os.environ.get("GROQ_API_KEY") |
| |
|
| | client = Groq(api_key=GROQ_API_KEY) |
| |
|
| | st.set_page_config(page_title="AI Recipe Generator", layout="centered") |
| | st.title("π¨βπ³ Smart Recipe Generator") |
| | st.caption("Tell me your ingredients and get 3 recipe options by calories!") |
| |
|
| | |
| | ingredients = st.text_input("π₯ What ingredients do you have?", placeholder="e.g. chicken, tomato, rice") |
| | preferred_cuisine = st.text_input("π What type of cuisine do you prefer?", placeholder="Optional: Chinese, Asian, Italian...") |
| |
|
| | if st.button("π½οΈ Generate Recipes") and ingredients.strip(): |
| | with st.spinner("Thinking of delicious recipes..."): |
| | prompt = f""" |
| | You are a smart recipe generator AI. The user has these ingredients: {ingredients}. |
| | They prefer this cuisine: {preferred_cuisine if preferred_cuisine else 'any'}. |
| | You must decide what types of dishes can be made and suggest 3 recipes: |
| | 1. One with low calories |
| | 2. One with moderate calories |
| | 3. One with high calories |
| | Give recipe names, steps, and estimated calories. |
| | """ |
| | chat_completion = client.chat.completions.create( |
| | messages=[{"role": "user", "content": prompt}], |
| | model="llama-3.3-70b-versatile" |
| | ) |
| |
|
| | recipes = chat_completion.choices[0].message.content |
| | st.success("π³ Recipes Generated!") |
| | st.markdown("### π Your Recipes") |
| | st.markdown(recipes) |
| | else: |
| | st.info("Please enter the ingredients to generate recipes.") |
| |
|