Spaces:
Sleeping
Sleeping
| import requests | |
| import pandas as pd | |
| # Function to fetch nutrition details | |
| def fetch_nutrition(query: str): | |
| api_url = f'https://api.api-ninjas.com/v1/nutrition?query={query}' | |
| headers = {'X-Api-Key': 'Hu4DkNyaIFT+E/FfCPRaYw==EUSFTIrXpCdQXrjH'} | |
| response = requests.get(api_url, headers=headers) | |
| if response.status_code == requests.codes.ok: | |
| data = response.json() | |
| if data: | |
| df = pd.DataFrame(data) | |
| # Drop unwanted columns | |
| df = df.drop(columns=['calories', 'serving_size_g', 'protein_g'], errors='ignore') | |
| return df | |
| return None | |