Spaces:
Runtime error
Runtime error
File size: 1,221 Bytes
04a3fe5 131543d 04a3fe5 131543d 04a3fe5 131543d 04a3fe5 |
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 |
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()
|