Spaces:
Sleeping
Sleeping
File size: 1,410 Bytes
1c11924 1ff9bc2 a9f80b5 1c11924 1ff9bc2 4523f25 1ff9bc2 890ed83 1ff9bc2 c59f12a a9f80b5 1c11924 | 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 | import os
import requests
import streamlit as st
st.set_page_config(page_title="Recipe Generator", layout="centered")
st.title("🍳 AI Recipe Generator")
st.write("Enter ingredients and get a recipe suggestion!")
ingredients = st.text_input("Enter ingredients (comma-separated):", placeholder="eggs, cheese, spinach")
if st.button("Generate Recipe"):
if ingredients:
with st.spinner("Generating recipe..."):
api_key = os.environ.get("GROQ_API_KEY")
prompt = (
f"Write a complete recipe using these ingredients: {ingredients}. "
"Include: a creative recipe name, ingredients with amounts, "
"numbered cooking steps, and estimated cooking time."
)
response = requests.post(
"https://api.groq.com/openai/v1/chat/completions",
headers={"Authorization": f"Bearer {api_key}"},
json={
"model": "llama-3.1-8b-instant",
"messages": [{"role": "user", "content": prompt}],
"max_tokens": 500,
"temperature": 0.7,
},
timeout=30,
)
response.raise_for_status()
recipe = response.json()["choices"][0]["message"]["content"]
st.success(recipe)
else:
st.warning("Please enter some ingredients!")
|