diff --git a/foodsnap/README.md b/foodsnap/README.md new file mode 100644 index 0000000..e82dda0 --- /dev/null +++ b/foodsnap/README.md @@ -0,0 +1,52 @@ +# FoodSnap AI - Simple Calorie Estimator CLI + +--- + +## 🚀 Project Overview + +**FoodSnap AI** is a lightweight Python command-line tool designed to estimate the caloric content and macronutrient breakdown (protein, carbs, fats) of a food item based on user input. It leverages a food nutrition API (such as Spoonacular) to provide accurate nutritional data quickly and easily — no manual lookup required! + +--- + +## ✨ Features + +- Accepts **food item name** as input via CLI. +- Retrieves **calories, protein, carbohydrates, and fat** estimates from an API. +- Minimalistic command-line interface — easy and fast to use. +- Built using Python and the popular `requests` library for HTTP requests. + +--- + +## 🛠️ Tech Stack + +- **Python 3.x** +- **requests** library +- **Spoonacular API** (or any equivalent food nutrition API) + +--- + +## ⚙️ Setup & Installation + +1. **Clone the repository** (if not already done): + bash + git clone https://github.com/YOUR_USERNAME/foodsnap-ai.git + cd foodsnap-ai + + +2. **Navigate to the `foodsnap` directory**: + bash + cd foodsnap + +3. **Install dependencies**: + bash + pip install requests +4. **Create or edit your main Python script**: + - The main script file is `main.py`. + - Use any text editor or IDE of your choice. + +## ▶️ How to Run + +Run the following command in your terminal: + +```bash +python main.py diff --git a/foodsnap/main.py b/foodsnap/main.py new file mode 100644 index 0000000..48ec03f --- /dev/null +++ b/foodsnap/main.py @@ -0,0 +1,19 @@ +import requests + +def get_nutrition(food_name, api_key): + url = f"https://api.spoonacular.com/recipes/guessNutrition?title={food_name}&apiKey={api_key}" + response = requests.get(url) + + if response.status_code == 200: + data = response.json() + print(f"Estimated Calories: {data['calories']['value']} kcal") + print(f"Fat: {data['fat']['value']} g") + print(f"Carbs: {data['carbs']['value']} g") + print(f"Protein: {data['protein']['value']} g") + else: + print("Error fetching data:", response.status_code, response.text) + +if __name__ == "__main__": + food = input("Enter the food item: ") + api_key = "2c303386a88c42af8870115216f3c85c" # Replace with your Spoonacular API key + get_nutrition(food, api_key)