File size: 1,606 Bytes
46b17f0
d0939c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 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.")