-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
53 lines (46 loc) · 1.56 KB
/
app.py
File metadata and controls
53 lines (46 loc) · 1.56 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import streamlit as st
import requests
import pandas as pd
st.set_page_config(page_title="Recipe Finder", page_icon="🍴")
st.markdown(
f"""
<style>
.stApp {{
background-image: url("https://4kwallpapers.com/images/wallpapers/ios-13-stock-ipados-dark-green-black-background-amoled-ipad-2560x1440-794.jpg");
background-attachment: fixed;
background-size: cover
}}
</style>
""",
unsafe_allow_html=True
)
st.title("Recipe Finder")
def get_recipes(ingredients, diet):
# api_key = "<your-api-key"
url = "https://api.spoonacular.com/recipes/complexSearch"
params = {
"apiKey": st.secrets["api_key"],
"query": ingredients,
"diet": diet,
"number": 10,
"addRecipeInformation": True
}
response = requests.get(url, params=params)
return response.json()
def main():
ingredients = st.text_input("Enter comma-separated ingredients (e.g. chicken, rice, broccoli): ")
diet = st.selectbox("Dietary restrictions", ["None", "Vegetarian", "Vegan", "Gluten-Free", "Ketogenic"])
if st.button("Find Recipes"):
if ingredients:
response = get_recipes(ingredients, diet)
results = response["results"]
if len(results) == 0:
st.write("No recipes found.")
else:
df = pd.DataFrame(results)
df = df[["title", "readyInMinutes", "servings", "sourceUrl"]]
st.write(df)
else:
st.write("Enter at least one ingredient")
if __name__ == "__main__":
main()