import streamlit as st import openai client = openai.OpenAI(api_key = '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') def generate_recipe(ingredients): prompt = f"Given the following ingredients: {', '.join(ingredients)}, give me a recipe for a lunch plate I can make with them. You don't have to use all of the ingredients." response = client.chat.completions.create( model="gpt-3.5-turbo", messages=[ {"role": "system", "content": "You are a kitchen assistant."}, {"role": "user", "content": prompt}] ) return response.choices[0].message.content.strip() def main(): st.title("Recipe Generator") ingredients_input = st.text_input("Enter the ingredients you have, separated by a comma:") if st.button("Show me a recipe"): ingredients = ingredients_input.split(',') ingredients = [ingredient.strip() for ingredient in ingredients if len(ingredient.strip())] if not len(ingredients): st.error("Please provide at least one ingredient.") else: recipe = generate_recipe(ingredients) st.subheader("Recipe:") st.write(recipe) if __name__ == "__main__": main()