Spaces:
Sleeping
Sleeping
| 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!") | |