Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from groq import Groq
|
| 4 |
+
|
| 5 |
+
# Load your GROQ API Key (set this in Hugging Face Secrets)
|
| 6 |
+
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
|
| 7 |
+
|
| 8 |
+
client = Groq(api_key=GROQ_API_KEY)
|
| 9 |
+
|
| 10 |
+
st.set_page_config(page_title="AI Recipe Generator", layout="centered")
|
| 11 |
+
st.title("π¨βπ³ Smart Recipe Generator")
|
| 12 |
+
st.caption("Tell me your ingredients and get 3 recipe options by calories!")
|
| 13 |
+
|
| 14 |
+
# Step 1: User input
|
| 15 |
+
ingredients = st.text_input("π₯ What ingredients do you have?", placeholder="e.g. chicken, tomato, rice")
|
| 16 |
+
preferred_cuisine = st.text_input("π What type of cuisine do you prefer?", placeholder="Optional: Chinese, Asian, Italian...")
|
| 17 |
+
|
| 18 |
+
if st.button("π½οΈ Generate Recipes") and ingredients.strip():
|
| 19 |
+
with st.spinner("Thinking of delicious recipes..."):
|
| 20 |
+
prompt = f"""
|
| 21 |
+
You are a smart recipe generator AI. The user has these ingredients: {ingredients}.
|
| 22 |
+
They prefer this cuisine: {preferred_cuisine if preferred_cuisine else 'any'}.
|
| 23 |
+
You must decide what types of dishes can be made and suggest 3 recipes:
|
| 24 |
+
1. One with low calories
|
| 25 |
+
2. One with moderate calories
|
| 26 |
+
3. One with high calories
|
| 27 |
+
Give recipe names, steps, and estimated calories.
|
| 28 |
+
"""
|
| 29 |
+
chat_completion = client.chat.completions.create(
|
| 30 |
+
messages=[{"role": "user", "content": prompt}],
|
| 31 |
+
model="llama-3.3-70b-versatile"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
recipes = chat_completion.choices[0].message.content
|
| 35 |
+
st.success("π³ Recipes Generated!")
|
| 36 |
+
st.markdown("### π Your Recipes")
|
| 37 |
+
st.markdown(recipes)
|
| 38 |
+
else:
|
| 39 |
+
st.info("Please enter the ingredients to generate recipes.")
|