From 9e16e12fc8dd02abe5b023cc4d9e97223ea7630b Mon Sep 17 00:00:00 2001 From: Shreya H S Date: Sun, 6 Oct 2024 15:40:43 +0530 Subject: [PATCH 1/2] Addition of recipe_finder through API using streamlit --- .../ApiPrograms/recipe_finder/.gitignore | 14 ++ .../recipe_finder/recipe_finder.py | 137 ++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 src/apps/pages/programs/ApiPrograms/recipe_finder/.gitignore create mode 100644 src/apps/pages/programs/ApiPrograms/recipe_finder/recipe_finder.py diff --git a/src/apps/pages/programs/ApiPrograms/recipe_finder/.gitignore b/src/apps/pages/programs/ApiPrograms/recipe_finder/.gitignore new file mode 100644 index 00000000..34785bfa --- /dev/null +++ b/src/apps/pages/programs/ApiPrograms/recipe_finder/.gitignore @@ -0,0 +1,14 @@ +# Ignore Python cache files +__pycache__/ + +# Ignore .env file for API keys +.env + +# Ignore virtual environment +venv/ + +# Ignore log files +*.log + +# Ignore compiled files +*.pyc \ No newline at end of file diff --git a/src/apps/pages/programs/ApiPrograms/recipe_finder/recipe_finder.py b/src/apps/pages/programs/ApiPrograms/recipe_finder/recipe_finder.py new file mode 100644 index 00000000..1994e179 --- /dev/null +++ b/src/apps/pages/programs/ApiPrograms/recipe_finder/recipe_finder.py @@ -0,0 +1,137 @@ +import streamlit as st +import requests +import os +from dotenv import load_dotenv + +# Load environment variables from .env file +load_dotenv() + +# Function to fetch recipes +def fetch_recipes(query): + api_key = os.getenv('SPOONACULAR_API_KEY') # Retrieve API key from environment variable + api_url = f"https://api.spoonacular.com/recipes/complexSearch?query={query}&apiKey={api_key}" + response = requests.get(api_url) + return response.json() +# Streamlit UI + +# Add custom CSS +st.write( + """ + + """, + unsafe_allow_html=True, +) + +# Display the title with the custom class +st.markdown('

Recipe Finder

', unsafe_allow_html=True) + +# Centered input box with placeholder text +st.markdown('
', unsafe_allow_html=True) +query = st.text_input("Ingredients or a dish name, you name it!", placeholder="Enter") +st.markdown('
', unsafe_allow_html=True) + +# Add custom CSS for styling +st.markdown( + """ + + """, + unsafe_allow_html=True, +) + +if query: + # Fetch recipes + recipes_data = fetch_recipes(query) + + # Extract the results list from the response + recipes = recipes_data.get('results', []) + + # Create a flex container for the recipes + st.markdown('
', unsafe_allow_html=True) + + # Display each recipe with the updated styles + for recipe in recipes: + recipe_url = f"https://spoonacular.com/recipes/{recipe['title'].replace(' ', '-').lower()}-{recipe['id']}" + st.markdown( + f""" + +
+ +
{recipe["title"]}
+
+
+ """, + unsafe_allow_html=True, + ) + + st.markdown('
', unsafe_allow_html=True) \ No newline at end of file From b7dd04d1489e466b2f2506a0d0c421677a62cb00 Mon Sep 17 00:00:00 2001 From: Shreya H S Date: Sun, 6 Oct 2024 15:43:35 +0530 Subject: [PATCH 2/2] ignoring vitual env --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 5d8b4bee..d7e9bb87 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ __pycache__/ # Virtual environment myenv /myenv + +/venv \ No newline at end of file