abdullahrehan's picture
Update app.py
46b17f0 verified
# Hello
import os
import streamlit as st
from 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 input
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.")