Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839import osimport streamlit as stfrom groq import Groq
# Load your GROQ API Key (set this in Hugging Face Secrets)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!")
# Step 1: User inputingredients = 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 calories2. One with moderate calories3. One with high caloriesGive 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.")app.pyAdded+39